Skip to content

Commit 7caa96a

Browse files
authored
[VL]Use isTimestamp/Varchar/Row func to check type (#8902)
1 parent b3c0052 commit 7caa96a

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc

+7-13
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ bool SubstraitToVeloxPlanValidator::parseVeloxType(
8989
}
9090

9191
bool SubstraitToVeloxPlanValidator::flattenSingleLevel(const TypePtr& type, std::vector<TypePtr>& out) {
92-
if (type->kind() != TypeKind::ROW) {
92+
if (!type->isRow()) {
9393
LOG_VALIDATION_MSG("Type is not a RowType.");
9494
return false;
9595
}
@@ -105,7 +105,7 @@ bool SubstraitToVeloxPlanValidator::flattenSingleLevel(const TypePtr& type, std:
105105
}
106106

107107
bool SubstraitToVeloxPlanValidator::flattenDualLevel(const TypePtr& type, std::vector<std::vector<TypePtr>>& out) {
108-
if (type->kind() != TypeKind::ROW) {
108+
if (!type->isRow()) {
109109
LOG_VALIDATION_MSG("Type is not a RowType.");
110110
return false;
111111
}
@@ -241,47 +241,41 @@ bool SubstraitToVeloxPlanValidator::validateScalarFunction(
241241

242242
bool SubstraitToVeloxPlanValidator::isAllowedCast(const TypePtr& fromType, const TypePtr& toType) {
243243
// Currently cast is not allowed for various categories, code has a bunch of rules
244-
// which define the cast categories and if we should offload to velox. Currently
244+
// which define the cast categories and if we should offload to velox. Currently,
245245
// the following categories are denied.
246246
//
247247
// 1. from/to isIntervalYearMonth is not allowed.
248248
// 2. Date to most categories except few supported types is not allowed.
249249
// 3. Timestamp to most categories except few supported types is not allowed.
250250
// 4. Certain complex types are not allowed.
251251

252-
TypeKind fromKind = fromType->kind();
253-
TypeKind toKind = toType->kind();
254-
255-
static const std::unordered_set<TypeKind> complexTypeList = {
256-
TypeKind::ARRAY, TypeKind::MAP, TypeKind::ROW, TypeKind::VARBINARY};
257-
258252
// Don't support isIntervalYearMonth.
259253
if (fromType->isIntervalYearMonth() || toType->isIntervalYearMonth()) {
260254
LOG_VALIDATION_MSG("Casting involving INTERVAL_YEAR_MONTH is not supported.");
261255
return false;
262256
}
263257

264258
// Limited support for DATE to X.
265-
if (fromType->isDate() && toKind != TypeKind::TIMESTAMP && toKind != TypeKind::VARCHAR) {
259+
if (fromType->isDate() && !toType->isTimestamp() && !toType->isVarchar()) {
266260
LOG_VALIDATION_MSG("Casting from DATE to " + toType->toString() + " is not supported.");
267261
return false;
268262
}
269263

270264
// Limited support for Timestamp to X.
271-
if (fromKind == TypeKind::TIMESTAMP && !(toType->isDate() || toKind == TypeKind::VARCHAR)) {
265+
if (fromType->isTimestamp() && !(toType->isDate() || toType->isVarchar())) {
272266
LOG_VALIDATION_MSG(
273267
"Casting from TIMESTAMP to " + toType->toString() + " is not supported or has incorrect result.");
274268
return false;
275269
}
276270

277271
// Limited support for X to Timestamp.
278-
if (toKind == TypeKind::TIMESTAMP && !fromType->isDate()) {
272+
if (toType->isTimestamp() && !fromType->isDate()) {
279273
LOG_VALIDATION_MSG("Casting from " + fromType->toString() + " to TIMESTAMP is not supported.");
280274
return false;
281275
}
282276

283277
// Limited support for Complex types.
284-
if (complexTypeList.find(fromKind) != complexTypeList.end()) {
278+
if (fromType->isArray() || fromType->isMap() || fromType->isRow() || fromType->isVarbinary()) {
285279
LOG_VALIDATION_MSG("Casting from " + fromType->toString() + " is not currently supported.");
286280
return false;
287281
}

0 commit comments

Comments
 (0)