use of io.prestosql.sql.planner.Plan in project hetu-core by openlookeng.
the class RuleAssert method matches.
public void matches(PlanMatchPattern pattern) {
RuleApplication ruleApplication = applyRule();
TypeProvider typeProvider = ruleApplication.types;
if (!ruleApplication.wasRuleApplied()) {
fail(format("%s did not fire for:\n%s", rule.getClass().getName(), formatPlan(plan, typeProvider)));
}
PlanNode actual = ruleApplication.getTransformedPlan();
if (actual == plan) {
// plans are not comparable, so we can only ensure they are not the same instance
fail(format("%s: rule fired but return the original plan:\n%s", rule.getClass().getName(), formatPlan(plan, typeProvider)));
}
if (!ImmutableSet.copyOf(plan.getOutputSymbols()).equals(ImmutableSet.copyOf(actual.getOutputSymbols()))) {
fail(format("%s: output schema of transformed and original plans are not equivalent\n" + "\texpected: %s\n" + "\tactual: %s", rule.getClass().getName(), plan.getOutputSymbols(), actual.getOutputSymbols()));
}
inTransaction(session -> {
assertPlan(session, metadata, ruleApplication.statsProvider, new Plan(actual, typeProvider, StatsAndCosts.empty()), ruleApplication.lookup, pattern);
return null;
});
}
use of io.prestosql.sql.planner.Plan in project hetu-core by openlookeng.
the class BasePlanTest method assertPlanWithSession.
protected void assertPlanWithSession(@Language("SQL") String sql, Session session, PlanMatchPattern pattern, List<PlanOptimizer> optimizers) {
queryRunner.inTransaction(session, transactionSession -> {
Plan actualPlan = queryRunner.createPlan(transactionSession, sql, optimizers, WarningCollector.NOOP);
PlanAssert.assertPlan(transactionSession, queryRunner.getMetadata(), queryRunner.getStatsCalculator(), actualPlan, pattern);
return null;
});
}
use of io.prestosql.sql.planner.Plan in project hetu-core by openlookeng.
the class TestUnion method testUnionOverSingleNodeAggregationAndUnion.
@Test
public void testUnionOverSingleNodeAggregationAndUnion() {
Plan plan = plan("SELECT count(*) FROM (" + "SELECT 1 FROM nation GROUP BY regionkey " + "UNION ALL (" + " SELECT 1 FROM nation " + " UNION ALL " + " SELECT 1 FROM nation))", LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, false);
List<PlanNode> remotes = searchFrom(plan.getRoot()).where(TestUnion::isRemoteExchange).findAll();
assertEquals(remotes.size(), 2, "There should be exactly two RemoteExchanges");
assertEquals(((ExchangeNode) remotes.get(0)).getType(), GATHER);
assertEquals(((ExchangeNode) remotes.get(1)).getType(), REPARTITION);
}
use of io.prestosql.sql.planner.Plan in project hetu-core by openlookeng.
the class TestUnion method testPartialRollupAggregationsWithUnion.
@Test
public void testPartialRollupAggregationsWithUnion() {
Plan plan = plan("SELECT orderstatus, sum(orderkey) FROM (SELECT orderkey, orderstatus FROM orders UNION ALL SELECT orderkey, orderstatus FROM orders) x GROUP BY ROLLUP (orderstatus)", LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, false);
assertAtMostOneAggregationBetweenRemoteExchanges(plan);
assertPlanIsFullyDistributed(plan);
}
use of io.prestosql.sql.planner.Plan in project hetu-core by openlookeng.
the class QueryAssertions method assertQuery.
private static void assertQuery(QueryRunner actualQueryRunner, Session actualQuerySession, @Language("SQL") String actual, H2QueryRunner h2QueryRunner, Session expectedQuerySession, @Language("SQL") String expected, boolean ensureOrdering, boolean compareUpdate, Optional<Consumer<Plan>> planAssertion) {
long start = System.nanoTime();
Optional<MaterializedResult> actualResultsOp = Optional.empty();
Plan queryPlan = null;
if (planAssertion.isPresent()) {
try {
MaterializedResultWithPlan resultWithPlan = actualQueryRunner.executeWithPlan(actualQuerySession, actual, WarningCollector.NOOP);
queryPlan = resultWithPlan.getQueryPlan();
actualResultsOp = Optional.of(resultWithPlan.getMaterializedResult().toTestTypes());
} catch (RuntimeException ex) {
fail("Execution of 'actual' query failed: " + actual, ex);
}
} else {
try {
actualResultsOp = Optional.of(actualQueryRunner.execute(actualQuerySession, actual).toTestTypes());
} catch (RuntimeException ex) {
fail("Execution of 'actual' query failed: " + actual, ex);
}
}
if (planAssertion.isPresent()) {
planAssertion.get().accept(queryPlan);
}
Duration actualTime = nanosSince(start);
long expectedStart = System.nanoTime();
Optional<MaterializedResult> expectedResultsOp = Optional.empty();
try {
expectedResultsOp = Optional.of(h2QueryRunner.execute(expectedQuerySession, expected, actualResultsOp.get().getTypes()));
} catch (RuntimeException ex) {
fail("Execution of 'expected' query failed: " + expected, ex);
}
Duration totalTime = nanosSince(start);
if (totalTime.compareTo(Duration.succinctDuration(1, SECONDS)) > 0) {
log.info("FINISHED in presto: %s, h2: %s, total: %s", actualTime, nanosSince(expectedStart), totalTime);
}
if (actualResultsOp.get().getUpdateType().isPresent() || actualResultsOp.get().getUpdateCount().isPresent()) {
if (!actualResultsOp.get().getUpdateType().isPresent()) {
fail("update count present without update type for query: \n" + actual);
}
if (!compareUpdate) {
fail("update type should not be present (use assertUpdate) for query: \n" + actual);
}
}
List<MaterializedRow> actualRows = actualResultsOp.get().getMaterializedRows();
List<MaterializedRow> expectedRows = expectedResultsOp.get().getMaterializedRows();
if (compareUpdate) {
if (!actualResultsOp.get().getUpdateType().isPresent()) {
fail("update type not present for query: \n" + actual);
}
if (!actualResultsOp.get().getUpdateCount().isPresent()) {
fail("update count not present for query: \n" + actual);
}
assertEquals(actualRows.size(), 1, "For query: \n " + actual + "\n:");
assertEquals(expectedRows.size(), 1, "For query: \n " + actual + "\n:");
MaterializedRow row = expectedRows.get(0);
assertEquals(row.getFieldCount(), 1, "For query: \n " + actual + "\n:");
assertEquals(row.getField(0), actualResultsOp.get().getUpdateCount().getAsLong(), "For query: \n " + actual + "\n:");
}
if (ensureOrdering) {
if (!actualRows.equals(expectedRows)) {
assertEquals(actualRows, expectedRows, "For query: \n " + actual + "\n:");
}
} else {
assertEqualsIgnoreOrder(actualRows, expectedRows, "For query: \n " + actual);
}
}
Aggregations