|
17 | 17 | import com.facebook.presto.spi.plan.OutputNode; |
18 | 18 | import com.facebook.presto.spi.plan.TableScanNode; |
19 | 19 | import com.facebook.presto.sql.planner.assertions.BasePlanTest; |
| 20 | +import com.facebook.presto.sql.planner.assertions.ExpressionMatcher; |
| 21 | +import com.facebook.presto.sql.planner.assertions.PlanMatchPattern; |
20 | 22 | import com.google.common.collect.ImmutableList; |
21 | 23 | import com.google.common.collect.ImmutableMap; |
22 | 24 | import org.testng.annotations.Test; |
23 | 25 |
|
| 26 | +import java.util.List; |
| 27 | +import java.util.Map; |
| 28 | + |
24 | 29 | import static com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE; |
25 | 30 | import static com.facebook.presto.SystemSessionProperties.JOIN_REORDERING_STRATEGY; |
26 | 31 | import static com.facebook.presto.spi.plan.JoinType.INNER; |
|
41 | 46 | import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.strictTableScan; |
42 | 47 | import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.tableScan; |
43 | 48 | import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values; |
44 | | -import static org.testng.Assert.fail; |
45 | 49 |
|
46 | 50 | public class TestPlanMatchingFramework |
47 | 51 | extends BasePlanTest |
@@ -200,47 +204,36 @@ public void testReferenceNonexistentAlias() |
200 | 204 | tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey")))); |
201 | 205 | } |
202 | 206 |
|
203 | | - /* |
204 | | - * There are so many ways for matches to fail that this is not likely to be generally useful. |
205 | | - * Pending better diagnostics, please leave this here, and restrict its use to simple queries |
206 | | - * that have few ways to not match a pattern, and functionality that is well-tested with |
207 | | - * positive tests. |
208 | | - */ |
209 | | - private void assertFails(Runnable runnable) |
210 | | - { |
211 | | - try { |
212 | | - runnable.run(); |
213 | | - fail("Plans should not have matched!"); |
214 | | - } |
215 | | - catch (AssertionError e) { |
216 | | - //ignored |
217 | | - } |
218 | | - } |
219 | | - |
220 | 207 | @Test |
221 | 208 | public void testStrictOutputExtraSymbols() |
222 | 209 | { |
223 | | - assertFails(() -> assertMinimallyOptimizedPlan("SELECT orderkey, extendedprice FROM lineitem", |
| 210 | + assertMinimallyOptimizedPlanDoesNotMatch( |
| 211 | + "SELECT orderkey, extendedprice FROM lineitem", |
224 | 212 | strictOutput(ImmutableList.of("ORDERKEY"), |
225 | | - tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey", |
226 | | - "EXTENDEDPRICE", "extendedprice"))))); |
| 213 | + tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey", |
| 214 | + "EXTENDEDPRICE", "extendedprice")))); |
227 | 215 | } |
228 | 216 |
|
229 | 217 | @Test |
230 | 218 | public void testStrictTableScanExtraSymbols() |
231 | 219 | { |
232 | | - assertFails(() -> assertMinimallyOptimizedPlan("SELECT orderkey, extendedprice FROM lineitem", |
233 | | - output(ImmutableList.of("ORDERKEY", "EXTENDEDPRICE"), |
234 | | - strictTableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey"))))); |
| 220 | + String sql = "SELECT orderkey, extendedprice FROM lineitem"; |
| 221 | + List<String> outputs = ImmutableList.of("ORDERKEY", "EXTENDEDPRICE"); |
| 222 | + PlanMatchPattern source = strictTableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey")); |
| 223 | + PlanMatchPattern output = output(outputs, source); |
| 224 | + assertMinimallyOptimizedPlanDoesNotMatch(sql, output); |
235 | 225 | } |
236 | 226 |
|
237 | 227 | @Test |
238 | 228 | public void testStrictProjectExtraSymbols() |
239 | 229 | { |
240 | | - assertFails(() -> assertMinimallyOptimizedPlan("SELECT discount, orderkey, 1 + orderkey FROM lineitem", |
241 | | - output(ImmutableList.of("ORDERKEY", "EXPRESSION"), |
242 | | - strictProject(ImmutableMap.of("EXPRESSION", expression("1 + ORDERKEY"), "ORDERKEY", expression("ORDERKEY")), |
243 | | - tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey")))))); |
| 230 | + String sql = "SELECT discount, orderkey, 1 + orderkey FROM lineitem"; |
| 231 | + List<String> outputs = ImmutableList.of("ORDERKEY", "EXPRESSION"); |
| 232 | + Map<String, ExpressionMatcher> assignments = ImmutableMap.of("EXPRESSION", expression("1 + ORDERKEY"), "ORDERKEY", expression("ORDERKEY")); |
| 233 | + PlanMatchPattern source = tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey")); |
| 234 | + PlanMatchPattern strict = strictProject(assignments, source); |
| 235 | + PlanMatchPattern output = output(outputs, strict); |
| 236 | + assertMinimallyOptimizedPlanDoesNotMatch(sql, output); |
244 | 237 | } |
245 | 238 |
|
246 | 239 | @Test(expectedExceptions = {IllegalStateException.class}, expectedExceptionsMessageRegExp = ".*already bound to expression.*") |
|
0 commit comments