|
27 | 27 | import java.util.Optional;
|
28 | 28 |
|
29 | 29 | import static com.facebook.presto.common.type.BigintType.BIGINT;
|
| 30 | +import static com.facebook.presto.common.type.DoubleType.DOUBLE; |
30 | 31 | import static com.facebook.presto.common.type.VarcharType.VARCHAR;
|
31 | 32 | import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.aggregation;
|
32 | 33 | import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.expression;
|
@@ -72,6 +73,31 @@ public void testDoesNotFireForIfWithElse()
|
72 | 73 | }).doesNotFire();
|
73 | 74 | }
|
74 | 75 |
|
| 76 | + @Test |
| 77 | + public void testDoesNotFireForNonDeterministicFunction() |
| 78 | + { |
| 79 | + tester().assertThat(new RewriteAggregationIfToFilter(getFunctionManager())) |
| 80 | + .on(p -> { |
| 81 | + VariableReferenceExpression a = p.variable("a", DOUBLE); |
| 82 | + VariableReferenceExpression ds = p.variable("ds", VARCHAR); |
| 83 | + return p.aggregation(ap -> ap.globalGrouping().step(AggregationNode.Step.FINAL) |
| 84 | + .addAggregation(p.variable("expr"), p.rowExpression("sum(a)")) |
| 85 | + .source(p.project( |
| 86 | + assignment(a, p.rowExpression("IF(ds > '2021-07-01', random())")), |
| 87 | + p.values(ds)))); |
| 88 | + }).doesNotFire(); |
| 89 | + tester().assertThat(new RewriteAggregationIfToFilter(getFunctionManager())) |
| 90 | + .on(p -> { |
| 91 | + VariableReferenceExpression a = p.variable("a", BIGINT); |
| 92 | + VariableReferenceExpression ds = p.variable("ds", VARCHAR); |
| 93 | + return p.aggregation(ap -> ap.globalGrouping().step(AggregationNode.Step.FINAL) |
| 94 | + .addAggregation(p.variable("expr"), p.rowExpression("sum(a)")) |
| 95 | + .source(p.project( |
| 96 | + assignment(a, p.rowExpression("IF(random() > DOUBLE '0.1', 1)")), |
| 97 | + p.values(ds)))); |
| 98 | + }).doesNotFire(); |
| 99 | + } |
| 100 | + |
75 | 101 | @Test
|
76 | 102 | public void testFireOneAggregation()
|
77 | 103 | {
|
|
0 commit comments