[Improve](InPredict) enhance in predict with array type (#31828)

This commit is contained in:
Benjaminwei
2024-03-11 21:22:32 +08:00
committed by yiguolei
parent 1509fbd538
commit ccd21a6ea4
10 changed files with 150 additions and 41 deletions

View File

@ -86,6 +86,18 @@ public class InPredicate extends Expression {
}
return;
}
if (children().get(0).getDataType().isArrayType()) {
// we should check in value list is all list type
for (int i = 1; i < children().size(); i++) {
if (!children().get(i).getDataType().isArrayType() && !children().get(i).getDataType().isNullType()) {
throw new AnalysisException("in predicate list should compare with struct type list, but got : "
+ children().get(i).getDataType().toSql());
}
}
return;
}
children().forEach(c -> {
if (c.getDataType().isObjectType()) {
throw new AnalysisException("in predicate could not contains object type: " + this.toSql());

View File

@ -954,7 +954,8 @@ public class TypeCoercionUtils {
if (inPredicate.getOptions().stream().map(Expression::getDataType)
.allMatch(dt -> dt.equals(inPredicate.getCompareExpr().getDataType()))) {
if (!supportCompare(inPredicate.getCompareExpr().getDataType())
&& !inPredicate.getCompareExpr().getDataType().isStructType()) {
&& !inPredicate.getCompareExpr().getDataType().isStructType() && !inPredicate.getCompareExpr()
.getDataType().isArrayType()) {
throw new AnalysisException("data type " + inPredicate.getCompareExpr().getDataType()
+ " could not used in InPredicate " + inPredicate.toSql());
}
@ -970,8 +971,13 @@ public class TypeCoercionUtils {
throw new AnalysisException("data type " + optionalCommonType.get()
+ " is not match " + inPredicate.getCompareExpr().getDataType() + " used in InPredicate");
}
if (inPredicate.getCompareExpr().getDataType().isArrayType() && optionalCommonType.isPresent()
&& !optionalCommonType.get().isArrayType()) {
throw new AnalysisException("data type " + optionalCommonType.get()
+ " is not match " + inPredicate.getCompareExpr().getDataType() + " used in InPredicate");
}
if (optionalCommonType.isPresent() && !supportCompare(optionalCommonType.get())
&& !optionalCommonType.get().isStructType()) {
&& !optionalCommonType.get().isStructType() && !optionalCommonType.get().isArrayType()) {
throw new AnalysisException("data type " + optionalCommonType.get()
+ " could not used in InPredicate " + inPredicate.toSql());
}