[Improve](Variant) support implicit cast to numeric and string type (#30029)

This commit is contained in:
lihangyu
2024-01-22 11:02:55 +08:00
committed by yiguolei
parent e5f1d8d7ec
commit 4480f751e6
4 changed files with 111 additions and 2 deletions

View File

@ -496,6 +496,14 @@ public class BinaryPredicate extends Predicate implements Writable {
SessionVariable.getEnableDecimal256());
}
// Variant can be implicit cast to numeric type and string type at present
if (t1.isVariantType() && (t2.isNumericType() || t2.isStringType())) {
return Type.fromPrimitiveType(t2);
}
if (t2.isVariantType() && (t1.isNumericType() || t1.isStringType())) {
return Type.fromPrimitiveType(t1);
}
return Type.DOUBLE;
}

View File

@ -271,9 +271,10 @@ public class MatchPredicate extends Predicate {
throw new AnalysisException("right operand of " + op.toString() + " must be of type STRING: " + toSql());
}
if (!getChild(0).getType().isStringType() && !getChild(0).getType().isArrayType()) {
if (!getChild(0).getType().isStringType() && !getChild(0).getType().isArrayType()
&& !getChild(0).getType().isVariantType()) {
throw new AnalysisException(
"left operand of " + op.toString() + " must be of type STRING or ARRAY: " + toSql());
"left operand of " + op.toString() + " must be of type STRING, ARRAY or VARIANT: " + toSql());
}
fn = getBuiltinFunction(op.toString(),
@ -295,6 +296,11 @@ public class MatchPredicate extends Predicate {
}
}
// CAST variant to right expr type
if (e1.type.isVariantType()) {
setChild(0, e1.castTo(e2.getType()));
}
if (e1 instanceof SlotRef) {
SlotRef slotRef = (SlotRef) e1;
SlotDescriptor slotDesc = slotRef.getDesc();