[Improve](InPredict) enhance in predict with struct type (#30840)

This commit is contained in:
amory
2024-02-22 11:25:06 +08:00
committed by yiguolei
parent 6096227fea
commit ad07dec0ed
10 changed files with 311 additions and 4 deletions

View File

@ -76,6 +76,16 @@ public class InPredicate extends Expression {
@Override
public void checkLegalityBeforeTypeCoercion() {
if (children().get(0).getDataType().isStructType()) {
// we should check in value list is all struct type
for (int i = 1; i < children().size(); i++) {
if (!children().get(i).getDataType().isStructType() && !children().get(i).getDataType().isNullType()) {
throw new AnalysisException("in predicate struct 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

@ -953,7 +953,8 @@ public class TypeCoercionUtils {
if (inPredicate.getOptions().stream().map(Expression::getDataType)
.allMatch(dt -> dt.equals(inPredicate.getCompareExpr().getDataType()))) {
if (!supportCompare(inPredicate.getCompareExpr().getDataType())) {
if (!supportCompare(inPredicate.getCompareExpr().getDataType())
&& !inPredicate.getCompareExpr().getDataType().isStructType()) {
throw new AnalysisException("data type " + inPredicate.getCompareExpr().getDataType()
+ " could not used in InPredicate " + inPredicate.toSql());
}
@ -964,7 +965,13 @@ public class TypeCoercionUtils {
.stream()
.map(Expression::getDataType).collect(Collectors.toList()),
true);
if (optionalCommonType.isPresent() && !supportCompare(optionalCommonType.get())) {
if (inPredicate.getCompareExpr().getDataType().isStructType() && optionalCommonType.isPresent()
&& !optionalCommonType.get().isStructType()) {
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()) {
throw new AnalysisException("data type " + optionalCommonType.get()
+ " could not used in InPredicate " + inPredicate.toSql());
}