Add QueryAssertions#assertQueryAndPlan that validates plan too
package com.facebook.presto.sql.query;
import com.facebook.presto.Session;
+import com.facebook.presto.sql.planner.Plan;
+import com.facebook.presto.sql.planner.assertions.PlanAssert;
+import com.facebook.presto.sql.planner.assertions.PlanMatchPattern;
import com.facebook.presto.testing.LocalQueryRunner;
import com.facebook.presto.testing.MaterializedResult;
import com.facebook.presto.testing.MaterializedRow;
@@ -22,6 +25,7 @@ import org.intellij.lang.annotations.Language;
import java.io.Closeable;
import java.util.List;
+import java.util.function.Consumer;
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
import static com.google.common.base.Strings.nullToEmpty;
@@ -61,6 +65,18 @@ class QueryAssertions
}
}
+ public void assertQueryAndPlan(
+ @Language("SQL") String actual,
+ @Language("SQL") String expected,
+ PlanMatchPattern pattern,
+ Consumer<Plan> planValidator)
+ {
+ assertQuery(actual, expected);
+ Plan plan = runner.createPlan(runner.getDefaultSession(), actual);
+ PlanAssert.assertPlan(runner.getDefaultSession(), runner.getMetadata(), runner.getStatsCalculator(), plan, pattern);
+ planValidator.accept(plan);
+ }
+
public void assertQuery(@Language("SQL") String actual, @Language("SQL") String expected)
{
assertQuery(actual, expected, false);
