in cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc [248:324]
bool SubstraitToVeloxPlanValidator::isAllowedCast(const TypePtr& fromType, const TypePtr& toType) {
// Currently cast is not allowed for various categories, code has a bunch of rules
// which define the cast categories and if we should offload to velox. Currently,
// the following categories are denied.
//
// 1. from/to isIntervalYearMonth is not allowed.
// 2. Date to most categories except few supported types is not allowed.
// 3. Timestamp to most categories except few supported types is not allowed.
// 4. Certain complex types are not allowed.
// Don't support isIntervalYearMonth.
if (fromType->isIntervalYearMonth() || toType->isIntervalYearMonth()) {
return false;
}
// Limited support for DATE to X.
if (fromType->isDate() && !toType->isTimestamp() && !toType->isVarchar()) {
return false;
}
// Limited support for Timestamp to X.
if (fromType->isTimestamp()) {
if (toType->isDecimal()) {
return false;
}
if (toType->isBigint()) {
return true;
}
if (toType->isDate() || toType->isVarchar()) {
return true;
}
return false;
}
// Limited support for X to Timestamp.
if (toType->isTimestamp()) {
if (fromType->isDecimal()) {
return false;
}
if (fromType->isDate()) {
return true;
}
if (fromType->isVarchar()) {
return true;
}
if (fromType->isTinyint() || fromType->isSmallint() || fromType->isInteger() || fromType->isBigint() ||
fromType->isDouble() || fromType->isReal()) {
return true;
}
return false;
}
if (fromType->isArray() && toType->isArray()) {
const auto& toElem = toType->asArray().elementType();
const auto& fromElem = fromType->asArray().elementType();
if (!isAllowedCast(fromElem, toElem)) {
return false;
}
return isSupportedArrayCast(fromElem, toElem);
}
// Limited support for Complex types.
if (fromType->isArray() || fromType->isMap() || fromType->isRow()) {
return false;
}
if (fromType->isVarbinary() && !toType->isVarchar()) {
return false;
}
return true;
}