Skip to content

Commit f365a2c

Browse files
committed
Enable tests to fail
1 parent faa3a55 commit f365a2c

File tree

3 files changed

+51
-29
lines changed

3 files changed

+51
-29
lines changed

presto-main/src/test/java/com/facebook/presto/sql/planner/TestPlanMatchingFramework.java

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717
import com.facebook.presto.spi.plan.OutputNode;
1818
import com.facebook.presto.spi.plan.TableScanNode;
1919
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;
2022
import com.google.common.collect.ImmutableList;
2123
import com.google.common.collect.ImmutableMap;
2224
import org.testng.annotations.Test;
2325

26+
import java.util.List;
27+
import java.util.Map;
28+
2429
import static com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE;
2530
import static com.facebook.presto.SystemSessionProperties.JOIN_REORDERING_STRATEGY;
2631
import static com.facebook.presto.spi.plan.JoinType.INNER;
@@ -41,7 +46,6 @@
4146
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.strictTableScan;
4247
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.tableScan;
4348
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values;
44-
import static org.testng.Assert.fail;
4549

4650
public class TestPlanMatchingFramework
4751
extends BasePlanTest
@@ -200,47 +204,36 @@ public void testReferenceNonexistentAlias()
200204
tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey"))));
201205
}
202206

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-
220207
@Test
221208
public void testStrictOutputExtraSymbols()
222209
{
223-
assertFails(() -> assertMinimallyOptimizedPlan("SELECT orderkey, extendedprice FROM lineitem",
210+
assertMinimallyOptimizedPlanDoesNotMatch(
211+
"SELECT orderkey, extendedprice FROM lineitem",
224212
strictOutput(ImmutableList.of("ORDERKEY"),
225-
tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey",
226-
"EXTENDEDPRICE", "extendedprice")))));
213+
tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey",
214+
"EXTENDEDPRICE", "extendedprice"))));
227215
}
228216

229217
@Test
230218
public void testStrictTableScanExtraSymbols()
231219
{
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);
235225
}
236226

237227
@Test
238228
public void testStrictProjectExtraSymbols()
239229
{
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);
244237
}
245238

246239
@Test(expectedExceptions = {IllegalStateException.class}, expectedExceptionsMessageRegExp = ".*already bound to expression.*")

presto-main/src/test/java/com/facebook/presto/sql/planner/assertions/BasePlanTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ protected void assertPlan(String sql, Session session, Optimizer.PlanStage stage
193193
});
194194
}
195195

196+
private void assertPlanDoesNotMatch(String sql, Session session, Optimizer.PlanStage stage, PlanMatchPattern pattern, List<PlanOptimizer> optimizers)
197+
{
198+
queryRunner.inTransaction(session, transactionSession -> {
199+
Plan actualPlan = queryRunner.createPlan(
200+
transactionSession,
201+
sql,
202+
optimizers,
203+
stage,
204+
WarningCollector.NOOP);
205+
PlanAssert.assertPlanDoesNotMatch(transactionSession, queryRunner.getMetadata(), queryRunner.getStatsCalculator(), actualPlan, pattern);
206+
return null;
207+
});
208+
}
209+
196210
protected void assertDistributedPlan(String sql, PlanMatchPattern pattern)
197211
{
198212
assertDistributedPlan(sql, getQueryRunner().getDefaultSession(), pattern);
@@ -218,6 +232,21 @@ protected void assertMinimallyOptimizedPlan(@Language("SQL") String sql, PlanMat
218232
assertPlan(sql, queryRunner.getDefaultSession(), Optimizer.PlanStage.OPTIMIZED, pattern, optimizers);
219233
}
220234

235+
protected void assertMinimallyOptimizedPlanDoesNotMatch(@Language("SQL") String sql, PlanMatchPattern pattern)
236+
{
237+
List<PlanOptimizer> optimizers = ImmutableList.of(
238+
new UnaliasSymbolReferences(queryRunner.getMetadata().getFunctionAndTypeManager()),
239+
new PruneUnreferencedOutputs(),
240+
new IterativeOptimizer(
241+
getMetadata(),
242+
new RuleStatsRecorder(),
243+
queryRunner.getStatsCalculator(),
244+
queryRunner.getCostCalculator(),
245+
ImmutableSet.of(new RemoveRedundantIdentityProjections())));
246+
247+
assertPlanDoesNotMatch(sql, queryRunner.getDefaultSession(), Optimizer.PlanStage.OPTIMIZED, pattern, optimizers);
248+
}
249+
221250
protected void assertPlanWithSession(@Language("SQL") String sql, Session session, boolean forceSingleNode, PlanMatchPattern pattern)
222251
{
223252
queryRunner.inTransaction(session, transactionSession -> {

presto-tests/src/test/java/com/facebook/presto/tests/TestMetadataManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void testMetadataIsClearedAfterQueryFailed()
115115
queryRunner.execute(sql);
116116
fail("expected exception");
117117
}
118-
catch (Throwable t) {
118+
catch (RuntimeException t) {
119119
// query should fail
120120
}
121121

0 commit comments

Comments
 (0)