[fix](Nereids) compound predicate need cast children to boolean (#27649)
This commit is contained in:
@ -76,6 +76,7 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalTVFRelation;
|
||||
import org.apache.doris.nereids.trees.plans.logical.UsingJoin;
|
||||
import org.apache.doris.nereids.trees.plans.visitor.InferPlanOutputAlias;
|
||||
import org.apache.doris.nereids.types.BooleanType;
|
||||
import org.apache.doris.nereids.util.ExpressionUtils;
|
||||
import org.apache.doris.nereids.util.TypeCoercionUtils;
|
||||
import org.apache.doris.qe.ConnectContext;
|
||||
@ -158,6 +159,7 @@ public class BindExpression implements AnalysisRuleFactory {
|
||||
Set<Expression> boundConjuncts = filter.getConjuncts().stream()
|
||||
.map(expr -> bindSlot(expr, filter.child(), ctx.cascadesContext))
|
||||
.map(expr -> bindFunction(expr, ctx.root, ctx.cascadesContext))
|
||||
.map(expr -> TypeCoercionUtils.castIfNotSameType(expr, BooleanType.INSTANCE))
|
||||
.collect(ImmutableSet.toImmutableSet());
|
||||
return new LogicalFilter<>(boundConjuncts, filter.child());
|
||||
})
|
||||
@ -211,10 +213,12 @@ public class BindExpression implements AnalysisRuleFactory {
|
||||
List<Expression> cond = join.getOtherJoinConjuncts().stream()
|
||||
.map(expr -> bindSlot(expr, join.children(), ctx.cascadesContext))
|
||||
.map(expr -> bindFunction(expr, ctx.root, ctx.cascadesContext))
|
||||
.map(expr -> TypeCoercionUtils.castIfNotSameType(expr, BooleanType.INSTANCE))
|
||||
.collect(Collectors.toList());
|
||||
List<Expression> hashJoinConjuncts = join.getHashJoinConjuncts().stream()
|
||||
.map(expr -> bindSlot(expr, join.children(), ctx.cascadesContext))
|
||||
.map(expr -> bindFunction(expr, ctx.root, ctx.cascadesContext))
|
||||
.map(expr -> TypeCoercionUtils.castIfNotSameType(expr, BooleanType.INSTANCE))
|
||||
.collect(Collectors.toList());
|
||||
return new LogicalJoin<>(join.getJoinType(),
|
||||
hashJoinConjuncts, cond, join.getHint(), join.getMarkJoinSlotReference(),
|
||||
@ -476,6 +480,7 @@ public class BindExpression implements AnalysisRuleFactory {
|
||||
return bindSlot(expr, childPlan, ctx.cascadesContext, false);
|
||||
})
|
||||
.map(expr -> bindFunction(expr, ctx.root, ctx.cascadesContext))
|
||||
.map(expr -> TypeCoercionUtils.castIfNotSameType(expr, BooleanType.INSTANCE))
|
||||
.collect(Collectors.toSet());
|
||||
checkIfOutputAliasNameDuplicatedForGroupBy(ImmutableList.copyOf(boundConjuncts),
|
||||
childPlan.getOutputExpressions());
|
||||
@ -492,6 +497,7 @@ public class BindExpression implements AnalysisRuleFactory {
|
||||
return bindSlot(expr, childPlan.children(), ctx.cascadesContext, false);
|
||||
})
|
||||
.map(expr -> bindFunction(expr, ctx.root, ctx.cascadesContext))
|
||||
.map(expr -> TypeCoercionUtils.castIfNotSameType(expr, BooleanType.INSTANCE))
|
||||
.collect(Collectors.toSet());
|
||||
checkIfOutputAliasNameDuplicatedForGroupBy(ImmutableList.copyOf(boundConjuncts),
|
||||
childPlan.getOutput().stream().map(NamedExpression.class::cast)
|
||||
|
||||
@ -22,7 +22,6 @@ import org.apache.doris.nereids.trees.expressions.Expression;
|
||||
import org.apache.doris.nereids.trees.plans.Plan;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
|
||||
import org.apache.doris.nereids.trees.plans.visitor.CustomRewriter;
|
||||
import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanRewriter;
|
||||
import org.apache.doris.nereids.types.BooleanType;
|
||||
@ -44,7 +43,7 @@ public class AdjustConjunctsReturnType extends DefaultPlanRewriter<Void> impleme
|
||||
|
||||
@Override
|
||||
public Plan visit(Plan plan, Void context) {
|
||||
return (LogicalPlan) super.visit(plan, context);
|
||||
return super.visit(plan, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -63,7 +63,7 @@ public class LogicalFilter<CHILD_TYPE extends Plan> extends LogicalUnary<CHILD_T
|
||||
}
|
||||
|
||||
public List<Expression> getExpressions() {
|
||||
return ImmutableList.of(getPredicate());
|
||||
return ImmutableList.copyOf(conjuncts);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -61,7 +61,7 @@ public class LogicalHaving<CHILD_TYPE extends Plan> extends LogicalUnary<CHILD_T
|
||||
}
|
||||
|
||||
public List<Expression> getExpressions() {
|
||||
return ImmutableList.of(getPredicate());
|
||||
return ImmutableList.copyOf(conjuncts);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1028,19 +1028,9 @@ public class TypeCoercionUtils {
|
||||
public static Expression processCompoundPredicate(CompoundPredicate compoundPredicate) {
|
||||
// check
|
||||
compoundPredicate.checkLegalityBeforeTypeCoercion();
|
||||
|
||||
compoundPredicate.children().forEach(e -> {
|
||||
if (!e.getDataType().isBooleanType() && !e.getDataType().isNullType()
|
||||
&& !(e instanceof SubqueryExpr)) {
|
||||
throw new AnalysisException(String.format(
|
||||
"Operand '%s' part of predicate " + "'%s' should return type 'BOOLEAN' but "
|
||||
+ "returns type '%s'.",
|
||||
e.toSql(), compoundPredicate.toSql(), e.getDataType()));
|
||||
}
|
||||
}
|
||||
);
|
||||
List<Expression> children = compoundPredicate.children().stream()
|
||||
.map(e -> e.getDataType().isNullType() ? new NullLiteral(BooleanType.INSTANCE) : e)
|
||||
.map(e -> e.getDataType().isNullType() ? new NullLiteral(BooleanType.INSTANCE)
|
||||
: castIfNotSameType(e, BooleanType.INSTANCE))
|
||||
.collect(Collectors.toList());
|
||||
return compoundPredicate.withChildren(children);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user