Search in sources :

Example 11 with PlanNode

use of io.prestosql.spi.plan.PlanNode 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;
    });
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) TypeProvider(io.prestosql.sql.planner.TypeProvider) Plan(io.prestosql.sql.planner.Plan) PlanPrinter.textLogicalPlan(io.prestosql.sql.planner.planprinter.PlanPrinter.textLogicalPlan) PlanAssert.assertPlan(io.prestosql.sql.planner.assertions.PlanAssert.assertPlan)

Example 12 with PlanNode

use of io.prestosql.spi.plan.PlanNode in project hetu-core by openlookeng.

the class RuleAssert method applyRule.

private RuleApplication applyRule() {
    PlanSymbolAllocator planSymbolAllocator = new PlanSymbolAllocator(types.allTypes());
    Memo memo = new Memo(idAllocator, plan);
    Lookup lookup = Lookup.from(planNode -> Stream.of(memo.resolve(planNode)));
    PlanNode memoRoot = memo.getNode(memo.getRootGroup());
    return inTransaction(session -> applyRule(rule, memoRoot, ruleContext(statsCalculator, costCalculator, planSymbolAllocator, memo, lookup, session)));
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) Lookup(io.prestosql.sql.planner.iterative.Lookup) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator) Memo(io.prestosql.sql.planner.iterative.Memo)

Example 13 with PlanNode

use of io.prestosql.spi.plan.PlanNode in project hetu-core by openlookeng.

the class TestVerifyOnlyOneOutputNode method testValidateSuccessful.

@Test
public void testValidateSuccessful() {
    // random seemingly valid plan
    PlanNode root = new OutputNode(idAllocator.getNextId(), new ProjectNode(idAllocator.getNextId(), new ValuesNode(idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of()), Assignments.of()), ImmutableList.of(), ImmutableList.of());
    new VerifyOnlyOneOutputNode().validate(root, null, null, null, null, WarningCollector.NOOP);
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) OutputNode(io.prestosql.sql.planner.plan.OutputNode) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 14 with PlanNode

use of io.prestosql.spi.plan.PlanNode in project hetu-core by openlookeng.

the class TestVerifyOnlyOneOutputNode method testValidateFailed.

@Test(expectedExceptions = IllegalStateException.class)
public void testValidateFailed() {
    // random plan with 2 output nodes
    PlanNode root = new OutputNode(idAllocator.getNextId(), new ExplainAnalyzeNode(idAllocator.getNextId(), new OutputNode(idAllocator.getNextId(), new ProjectNode(idAllocator.getNextId(), new ValuesNode(idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of()), Assignments.of()), ImmutableList.of(), ImmutableList.of()), new Symbol("a"), false), ImmutableList.of(), ImmutableList.of());
    new VerifyOnlyOneOutputNode().validate(root, null, null, null, null, WarningCollector.NOOP);
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) OutputNode(io.prestosql.sql.planner.plan.OutputNode) PlanNode(io.prestosql.spi.plan.PlanNode) ExplainAnalyzeNode(io.prestosql.sql.planner.plan.ExplainAnalyzeNode) Symbol(io.prestosql.spi.plan.Symbol) ProjectNode(io.prestosql.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 15 with PlanNode

use of io.prestosql.spi.plan.PlanNode in project hetu-core by openlookeng.

the class TestExternalFunctionPushDownChecker method testWindowNodeWithExternalCall.

@Test(expectedExceptions = ExternalFunctionPushDownChecker.IllegalExternalFunctionUsageException.class, expectedExceptionsMessageRegExp = "The external function jdbc.v1.foo does not support to push down to data source for this query.")
public void testWindowNodeWithExternalCall() {
    WindowNode.Frame frame = new WindowNode.Frame(Types.WindowFrameType.RANGE, UNBOUNDED_PRECEDING, Optional.empty(), CURRENT_ROW, Optional.empty(), Optional.empty(), Optional.empty());
    PlanNode root = builder.window(new WindowNode.Specification(ImmutableList.of(columnA), Optional.empty()), ImmutableMap.of(columnB, new WindowNode.Function(externalFooCall1, ImmutableList.of(), frame)), builder.values(columnA));
    validatePlan(root);
}
Also used : WindowNode(io.prestosql.spi.plan.WindowNode) PlanNode(io.prestosql.spi.plan.PlanNode) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Aggregations

PlanNode (io.prestosql.spi.plan.PlanNode)241 Test (org.testng.annotations.Test)100 Symbol (io.prestosql.spi.plan.Symbol)98 RowExpression (io.prestosql.spi.relation.RowExpression)52 ImmutableList (com.google.common.collect.ImmutableList)49 ProjectNode (io.prestosql.spi.plan.ProjectNode)46 Expression (io.prestosql.sql.tree.Expression)46 TableScanNode (io.prestosql.spi.plan.TableScanNode)45 JoinNode (io.prestosql.spi.plan.JoinNode)42 Optional (java.util.Optional)42 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)41 FilterNode (io.prestosql.spi.plan.FilterNode)39 CallExpression (io.prestosql.spi.relation.CallExpression)39 ImmutableMap (com.google.common.collect.ImmutableMap)38 List (java.util.List)38 Map (java.util.Map)36 AggregationNode (io.prestosql.spi.plan.AggregationNode)35 BasePlanTest (io.prestosql.sql.planner.assertions.BasePlanTest)34 Assignments (io.prestosql.spi.plan.Assignments)33 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)32