|
14 | 14 | package com.facebook.presto.cost; |
15 | 15 |
|
16 | 16 | import com.facebook.presto.Session; |
| 17 | +import com.facebook.presto.common.type.DoubleType; |
17 | 18 | import com.facebook.presto.common.type.VarcharType; |
18 | 19 | import com.facebook.presto.metadata.MetadataManager; |
19 | 20 | import com.facebook.presto.spi.relation.RowExpression; |
20 | 21 | import com.facebook.presto.spi.relation.VariableReferenceExpression; |
21 | 22 | import com.facebook.presto.sql.InMemoryExpressionOptimizerProvider; |
22 | 23 | import com.facebook.presto.sql.TestingRowExpressionTranslator; |
23 | 24 | import com.facebook.presto.sql.planner.TypeProvider; |
| 25 | +import com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder; |
24 | 26 | import com.facebook.presto.sql.tree.Expression; |
25 | 27 | import com.google.common.collect.ImmutableList; |
26 | 28 | import org.testng.annotations.BeforeClass; |
|
37 | 39 | import static java.lang.Double.POSITIVE_INFINITY; |
38 | 40 | import static java.lang.String.format; |
39 | 41 | import static org.testng.Assert.assertEquals; |
| 42 | +import static org.testng.Assert.assertNotEquals; |
40 | 43 |
|
41 | 44 | public abstract class AbstractTestFilterStatsCalculator |
42 | 45 | { |
@@ -605,6 +608,30 @@ public void testInPredicateFilter() |
605 | 608 | .nullsFraction(0.0)); |
606 | 609 | } |
607 | 610 |
|
| 611 | + @Test |
| 612 | + public void testComplicatedAndOr() |
| 613 | + { |
| 614 | + Expression exp = expression("name <> 'business'"); |
| 615 | + TypeProvider customTypes = TypeProvider.fromVariables(ImmutableList.<VariableReferenceExpression>builder() |
| 616 | + .add(new VariableReferenceExpression(Optional.empty(), "name", MEDIUM_VARCHAR_TYPE)) |
| 617 | + .build()); |
| 618 | + |
| 619 | + RowExpression rowExpression = translator.translateAndOptimize(exp, customTypes); |
| 620 | + |
| 621 | + VariableStatsEstimate nameStats = VariableStatsEstimate.builder() |
| 622 | + .setNullsFraction(0D) |
| 623 | + .setDistinctValuesCount(1D) |
| 624 | + .build(); |
| 625 | + |
| 626 | + PlanNodeStatsEstimate inputStats = PlanNodeStatsEstimate.builder() |
| 627 | + .addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "name", MEDIUM_VARCHAR_TYPE), nameStats) |
| 628 | + .setOutputRowCount(100D) |
| 629 | + .build(); |
| 630 | + |
| 631 | + PlanNodeStatsEstimate rowExpressionStatsEstimate = statsCalculator.filterStats(inputStats, rowExpression, session); |
| 632 | + assertNotEquals(rowExpressionStatsEstimate.getOutputRowCount(), 0D, 0.0001D); |
| 633 | + } |
| 634 | + |
608 | 635 | protected PlanNodeStatsAssertion assertExpression(String expression) |
609 | 636 | { |
610 | 637 | return assertExpression(expression(expression)); |
|
0 commit comments