Skip to content

Commit

Permalink
fix ut
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Nov 26, 2024
1 parent 80929c0 commit 6806f90
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Extract common expr for `CompoundPredicate`.
Expand All @@ -60,12 +61,20 @@ public List<ExpressionPatternMatcher<? extends Expression>> buildRules() {

private static Expression extractCommonFactor(CompoundPredicate originExpr) {
// fast return
boolean canExtract = false;
Set<Expression> childrenSet = new LinkedHashSet<>();
for (Expression child : originExpr.children()) {
if (!(child instanceof CompoundPredicate || child instanceof BooleanLiteral)) {
return originExpr;
if ((child instanceof CompoundPredicate || child instanceof BooleanLiteral)) {
canExtract = true;
}
childrenSet.add(child);
}
if (!canExtract) {
if (childrenSet.size() != originExpr.children().size()) {
return originExpr.withChildren(childrenSet.stream().collect(Collectors.toList()));
}
return originExpr;
}

// flatten same type to a list
// e.g. ((a and (b or c)) and c) -> [a, (b or c), c]
List<Expression> flatten = ExpressionUtils.extract(originExpr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Statistics visitAnd(And and, EstimationContext context) {
Preconditions.checkArgument(children.size() > 1, "and expression abnormal: " + and);
for (Expression child : children) {
outputStats = child.accept(this, new EstimationContext(inputStats));
outputStats.normalizeColumnStatistics(context.statistics.getRowCount());
outputStats.normalizeColumnStatistics(inputStats.getRowCount(), true);
inputStats = outputStats;
}
return outputStats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void testSimplify() {
assertRewrite("TA + TC = 1 and TA + TC = 3", "(TA + TC) is null and null");
assertRewriteNotNull("TA + TC in (1) and TA + TC in (3)", "FALSE");
assertRewrite("TA + TC in (1) and TA + TC in (3)", "(TA + TC) is null and null");
assertRewrite("TA + TC in (1) and TA + TC in (1)", "TA + TC = 1");
assertRewrite("TA + TC in (1) and TA + TC in (1)", "(TA + TC) IN (1)");
assertRewriteNotNull("(TA + TC > 3 and TA + TC < 1) and TB < 5", "FALSE");
assertRewrite("(TA + TC > 3 and TA + TC < 1) and TB < 5", "(TA + TC) is null and null and TB < 5");
assertRewrite("(TA + TC > 3 and TA + TC < 1) or TB < 5", "((TA + TC) is null and null) OR TB < 5");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void testInferNotNullFromFilterAndEliminateOuter2() {
innerLogicalJoin(
logicalOlapScan(),
logicalFilter().when(
f -> f.getPredicate().toString().equals("((id#0 = 4) OR (id#0 > 4))"))
f -> f.getPredicate().toString().equals("OR[(id#0 = 4),(id#0 > 4)]"))
)

);
Expand All @@ -69,11 +69,11 @@ void testInferNotNullFromFilterAndEliminateOuter3() {
logicalFilter(
leftOuterLogicalJoin(
logicalFilter().when(
f -> f.getPredicate().toString().equals("((id#0 = 4) OR (id#0 > 4))")),
f -> f.getPredicate().toString().equals("OR[(id#0 = 4),(id#0 > 4)]")),
logicalOlapScan()
)
).when(f -> f.getPredicate().toString()
.equals("((id#0 = 4) OR ((id#0 > 4) AND score#3 IS NULL))"))
.equals("OR[(id#0 = 4),AND[(id#0 > 4),score#3 IS NULL]]"))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ void testMultiAndWithNull() {

FilterEstimation filterEstimation = new FilterEstimation();
Statistics result = filterEstimation.estimate(allAnd, stats);
Assertions.assertEquals(result.getRowCount(), 2109.16, 0.01);
Assertions.assertEquals(result.getRowCount(), 2109.0, 10);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void testFirstPartWithoutLowerBound() throws AnalysisException {
RangePartitionItem item1 = new RangePartitionItem(range1);

Set<Expression> predicates = UpdateMvByPartitionCommand.constructPredicates(Sets.newHashSet(item1), "s");
Assertions.assertEquals("((s < 1) OR s IS NULL)", predicates.iterator().next().toSql());
Assertions.assertEquals("OR[(s < 1),s IS NULL]", predicates.iterator().next().toSql());

}

Expand Down Expand Up @@ -82,6 +82,6 @@ void testNull() throws AnalysisException {
listPartitionItem = new ListPartitionItem(ImmutableList.of(v1, v2));
expr = UpdateMvByPartitionCommand.constructPredicates(Sets.newHashSet(listPartitionItem), "s").iterator()
.next();
Assertions.assertEquals("(s IS NULL OR s IN (1))", expr.toSql());
Assertions.assertEquals("OR[s IS NULL,s IN (1)]", expr.toSql());
}
}

0 comments on commit 6806f90

Please sign in to comment.