Search in sources :

Example 26 with PlanNode

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

the class TestMemo method testEvictStatsOnReplace.

@Test
public void testEvictStatsOnReplace() {
    PlanNode y = node();
    PlanNode x = node(y);
    Memo memo = new Memo(idAllocator, x);
    int xGroup = memo.getRootGroup();
    int yGroup = getChildGroup(memo, memo.getRootGroup());
    PlanNodeStatsEstimate xStats = PlanNodeStatsEstimate.builder().setOutputRowCount(42).build();
    PlanNodeStatsEstimate yStats = PlanNodeStatsEstimate.builder().setOutputRowCount(55).build();
    memo.storeStats(yGroup, yStats);
    memo.storeStats(xGroup, xStats);
    assertEquals(memo.getStats(yGroup), Optional.of(yStats));
    assertEquals(memo.getStats(xGroup), Optional.of(xStats));
    memo.replace(yGroup, node(), "rule");
    assertEquals(memo.getStats(yGroup), Optional.empty());
    assertEquals(memo.getStats(xGroup), Optional.empty());
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) PlanNodeStatsEstimate(io.prestosql.cost.PlanNodeStatsEstimate) Test(org.testng.annotations.Test)

Example 27 with PlanNode

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

the class TestUtil method createExchangePlanFragment.

private static PlanFragment createExchangePlanFragment(RowExpression expr) {
    Symbol testSymbol = new Symbol("a");
    Map<Symbol, ColumnHandle> scanAssignments = ImmutableMap.<Symbol, ColumnHandle>builder().put(testSymbol, new TestingMetadata.TestingColumnHandle("a")).build();
    Map<Symbol, ColumnHandle> assignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(testSymbol)));
    TableScanNode tableScanNode = new TableScanNode(new PlanNodeId(UUID.randomUUID().toString()), makeTableHandle(TupleDomain.none()), ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.none(), Optional.empty(), ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false);
    PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata());
    FilterNode filterNode = planBuilder.filter(expr, tableScanNode);
    PlanNode planNode = new LimitNode(new PlanNodeId("limit"), filterNode, 1, false);
    ImmutableMap.Builder<Symbol, Type> types = ImmutableMap.builder();
    for (Symbol symbol : planNode.getOutputSymbols()) {
        types.put(symbol, VARCHAR);
    }
    return new PlanFragment(new PlanFragmentId("limit_fragment_id"), planNode, types.build(), SOURCE_DISTRIBUTION, ImmutableList.of(planNode.getId()), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), planNode.getOutputSymbols()), ungroupedExecution(), StatsAndCosts.empty(), Optional.empty(), Optional.empty(), Optional.empty());
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Symbol(io.prestosql.spi.plan.Symbol) PartitioningScheme(io.prestosql.sql.planner.PartitioningScheme) FilterNode(io.prestosql.spi.plan.FilterNode) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) PlanFragment(io.prestosql.sql.planner.PlanFragment) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) Type(io.prestosql.spi.type.Type) PlanNode(io.prestosql.spi.plan.PlanNode) TableScanNode(io.prestosql.spi.plan.TableScanNode) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) LimitNode(io.prestosql.spi.plan.LimitNode) PlanFragmentId(io.prestosql.sql.planner.plan.PlanFragmentId) UUID(java.util.UUID)

Example 28 with PlanNode

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

the class PlanAssert method assertPlan.

public static void assertPlan(Session session, Metadata metadata, StatsProvider statsProvider, Plan actual, Lookup lookup, PlanMatchPattern pattern) {
    MatchResult matches = actual.getRoot().accept(new PlanMatchingVisitor(session, metadata, statsProvider, lookup), pattern);
    if (!matches.isMatch()) {
        String formattedPlan = textLogicalPlan(actual.getRoot(), actual.getTypes(), metadata, StatsAndCosts.empty(), session, 0, false);
        PlanNode resolvedPlan = resolveGroupReferences(actual.getRoot(), lookup);
        String resolvedFormattedPlan = textLogicalPlan(resolvedPlan, actual.getTypes(), metadata, StatsAndCosts.empty(), session, 0, false);
        throw new AssertionError(format("Plan does not match, expected [\n\n%s\n] but found [\n\n%s\n] which resolves to [\n\n%s\n]", pattern, formattedPlan, resolvedFormattedPlan));
    }
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode)

Example 29 with PlanNode

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

the class TestTypeValidator method testInvalidProject.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'expr(_[0-9]+)?' is expected to be bigint, but the actual type is integer")
public void testInvalidProject() {
    Expression expression1 = new Cast(toSymbolReference(columnB), StandardTypes.INTEGER);
    Expression expression2 = new Cast(toSymbolReference(columnA), StandardTypes.INTEGER);
    Assignments assignments = Assignments.builder().put(planSymbolAllocator.newSymbol(expression1, BIGINT), // should be INTEGER
    castToRowExpression(expression1)).put(planSymbolAllocator.newSymbol(expression1, INTEGER), castToRowExpression(expression2)).build();
    PlanNode node = new ProjectNode(newId(), baseTableScan, assignments);
    assertTypesValid(node);
}
Also used : Cast(io.prestosql.sql.tree.Cast) PlanNode(io.prestosql.spi.plan.PlanNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Expression(io.prestosql.sql.tree.Expression) Assignments(io.prestosql.spi.plan.Assignments) ProjectNode(io.prestosql.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 30 with PlanNode

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

the class TestTypeValidator method testValidWindow.

@Test
public void testValidWindow() {
    Symbol windowSymbol = planSymbolAllocator.newSymbol("sum", DOUBLE);
    FunctionHandle functionHandle = FUNCTION_MANAGER.lookupFunction("sum", fromTypes(DOUBLE));
    WindowNode.Frame frame = new WindowNode.Frame(WindowFrameType.RANGE, FrameBoundType.UNBOUNDED_PRECEDING, Optional.empty(), FrameBoundType.UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty());
    WindowNode.Function function = new WindowNode.Function(call("sum", functionHandle, DOUBLE, ImmutableList.of(VariableReferenceSymbolConverter.toVariableReference(columnC, DOUBLE))), ImmutableList.of(VariableReferenceSymbolConverter.toVariableReference(columnC, DOUBLE)), frame);
    WindowNode.Specification specification = new WindowNode.Specification(ImmutableList.of(), Optional.empty());
    PlanNode node = new WindowNode(newId(), baseTableScan, specification, ImmutableMap.of(windowSymbol, function), Optional.empty(), ImmutableSet.of(), 0);
    assertTypesValid(node);
}
Also used : WindowNode(io.prestosql.spi.plan.WindowNode) PlanNode(io.prestosql.spi.plan.PlanNode) Symbol(io.prestosql.spi.plan.Symbol) FunctionHandle(io.prestosql.spi.function.FunctionHandle) Test(org.testng.annotations.Test)

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