Skip to content

Commit

Permalink
fix p0
Browse files Browse the repository at this point in the history
  • Loading branch information
LiBinfeng-01 committed Oct 30, 2024
1 parent 095f315 commit f4952b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ public class Rewriter extends AbstractBatchJobExecutor {
),
custom(RuleType.COLUMN_PRUNING, ColumnPruning::new),
bottomUp(RuleSet.PUSH_DOWN_FILTERS),
bottomUp(new EliminateNotNull()),
custom(RuleType.ELIMINATE_UNNECESSARY_PROJECT, EliminateUnnecessaryProject::new)
),
topic("adjust preagg status",
Expand All @@ -433,6 +432,7 @@ public class Rewriter extends AbstractBatchJobExecutor {
// SORT_PRUNING should be applied after mergeLimit
custom(RuleType.ELIMINATE_SORT, EliminateSort::new),
bottomUp(
new EliminateNotNull(),
new EliminateEmptyRelation(),
// after eliminate empty relation under union, we could get
// limit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public abstract class Expression extends AbstractTreeNode<Expression> implements
private final Supplier<Set<Slot>> inputSlots = Suppliers.memoize(
() -> collect(e -> e instanceof Slot && !(e instanceof ArrayItemSlot)));
private final int fastChildrenHashCode;
private boolean inferNotNull = false;

protected Expression(Expression... children) {
super(children);
Expand Down Expand Up @@ -176,6 +177,14 @@ protected Expression(List<Expression> children, boolean inferred) {
this.hasUnbound = hasUnbound || this instanceof Unbound;
}

public void setInferNotNull(boolean inferNotNull) {
this.inferNotNull = inferNotNull;
}

public boolean isInferNotNull() {
return inferNotNull;
}

private void checkLimit() {
if (depth > Config.expr_depth_limit) {
throw new AnalysisException(String.format("Exceeded the maximum depth of an "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ private static boolean isNullOrFalse(Expression expression) {
public static Set<Slot> inferNotNullSlots(Set<Expression> predicates, CascadesContext cascadesContext) {
ImmutableSet.Builder<Slot> notNullSlots = ImmutableSet.builderWithExpectedSize(predicates.size());
for (Expression predicate : predicates) {
if (predicate.isInferNotNull()) {
continue;
}
for (Slot slot : predicate.getInputSlots()) {
Map<Expression, Expression> replaceMap = new HashMap<>();
Literal nullLiteral = new NullLiteral(slot.getDataType());
Expand All @@ -605,6 +608,7 @@ public static Set<Slot> inferNotNullSlots(Set<Expression> predicates, CascadesCo
new ExpressionRewriteContext(cascadesContext)
);
if (evalExpr.isNullLiteral() || BooleanLiteral.FALSE.equals(evalExpr)) {
predicate.setInferNotNull(true);
notNullSlots.add(slot);
}
}
Expand All @@ -618,7 +622,7 @@ public static Set<Slot> inferNotNullSlots(Set<Expression> predicates, CascadesCo
public static Set<Expression> inferNotNull(Set<Expression> predicates, CascadesContext cascadesContext) {
ImmutableSet.Builder<Expression> newPredicates = ImmutableSet.builderWithExpectedSize(predicates.size());
for (Slot slot : inferNotNullSlots(predicates, cascadesContext)) {
newPredicates.add(new Not(new IsNull(slot), false));
newPredicates.add(new Not(new IsNull(slot), false).withInferred(true));
}
return newPredicates.build();
}
Expand Down

0 comments on commit f4952b4

Please sign in to comment.