Search in sources :

Example 1 with UnionNode

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

the class TestTypeValidator method testInvalidUnion.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'output(_[0-9]+)?' is expected to be date, but the actual type is bigint")
public void testInvalidUnion() {
    Symbol outputSymbol = planSymbolAllocator.newSymbol("output", DATE);
    ListMultimap<Symbol, Symbol> mappings = ImmutableListMultimap.<Symbol, Symbol>builder().put(outputSymbol, columnD).put(outputSymbol, // should be a symbol with DATE type
    columnA).build();
    PlanNode node = new UnionNode(newId(), ImmutableList.of(baseTableScan, baseTableScan), mappings, ImmutableList.copyOf(mappings.keySet()));
    assertTypesValid(node);
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) UnionNode(io.prestosql.spi.plan.UnionNode) Symbol(io.prestosql.spi.plan.Symbol) Test(org.testng.annotations.Test)

Example 2 with UnionNode

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

the class TestStarTreeAggregationRule method testSupportedProjectNode.

@Test
public void testSupportedProjectNode() {
    // node is projectNode and expression instance of cast
    Assignments assignment1 = Assignments.builder().put(columnCustkey, new VariableReferenceExpression(columnCustkey.getName(), custkeyHandle.getType())).build();
    Optional<PlanNode> planNode1 = Optional.of(new ProjectNode(newId(), baseTableScan, assignment1));
    assertTrue(CubeOptimizerUtil.supportedProjectNode(planNode1));
    // not projectNode
    ListMultimap<Symbol, Symbol> mappings = ImmutableListMultimap.<Symbol, Symbol>builder().put(output, columnOrderkey).put(output, columnOrderkey).build();
    Optional<PlanNode> planNode2 = Optional.of(new UnionNode(newId(), ImmutableList.of(baseTableScan, baseTableScan), mappings, ImmutableList.copyOf(mappings.keySet())));
    assertFalse(CubeOptimizerUtil.supportedProjectNode(planNode2));
    // expression not instance of Cast
    Assignments assignment2 = Assignments.builder().put(columnCustkey, new InputReferenceExpression(1, INTEGER)).build();
    Optional<PlanNode> planNode3 = Optional.of(new ProjectNode(newId(), baseTableScan, assignment2));
    assertFalse(CubeOptimizerUtil.supportedProjectNode(planNode3));
    // expression is instance of SymbolReference OR Literal
    Assignments assignment3 = Assignments.builder().put(columnCustkey, // should be INTEGER
    new VariableReferenceExpression(columnCustkey.getName(), custkeyHandle.getType())).build();
    Optional<PlanNode> planNode4 = Optional.of(new ProjectNode(newId(), baseTableScan, assignment3));
    assertTrue(CubeOptimizerUtil.supportedProjectNode(planNode4));
    // empty node
    Optional<PlanNode> emptyPlanNode = Optional.empty();
    assertTrue(CubeOptimizerUtil.supportedProjectNode(emptyPlanNode));
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) UnionNode(io.prestosql.spi.plan.UnionNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) Symbol(io.prestosql.spi.plan.Symbol) Assignments(io.prestosql.spi.plan.Assignments) ProjectNode(io.prestosql.spi.plan.ProjectNode) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Example 3 with UnionNode

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

the class TestCostCalculator method testUnion.

@Test
public void testUnion() {
    TableScanNode ts1 = tableScan("ts1", "orderkey");
    TableScanNode ts2 = tableScan("ts2", "orderkey_0");
    ImmutableListMultimap.Builder<Symbol, Symbol> outputMappings = ImmutableListMultimap.builder();
    outputMappings.put(new Symbol("orderkey_1"), new Symbol("orderkey"));
    outputMappings.put(new Symbol("orderkey_1"), new Symbol("orderkey_0"));
    UnionNode union = new UnionNode(new PlanNodeId("union"), ImmutableList.of(ts1, ts2), outputMappings.build(), ImmutableList.of(new Symbol("orderkey_1")));
    Map<String, PlanNodeStatsEstimate> stats = ImmutableMap.of("ts1", statsEstimate(ts1, 4000), "ts2", statsEstimate(ts2, 1000), "union", statsEstimate(ts1, 5000));
    Map<String, PlanCostEstimate> costs = ImmutableMap.of("ts1", cpuCost(1000), "ts2", cpuCost(1000));
    Map<String, Type> types = ImmutableMap.of("orderkey", BIGINT, "orderkey_0", BIGINT, "orderkey_1", BIGINT);
    assertCost(union, costs, stats, types).cpu(2000).memory(0).network(0);
    assertCostEstimatedExchanges(union, costs, stats, types).cpu(2000).memory(0).network(5000 * IS_NULL_OVERHEAD);
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) Type(io.prestosql.spi.type.Type) TableScanNode(io.prestosql.spi.plan.TableScanNode) UnionNode(io.prestosql.spi.plan.UnionNode) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Test(org.testng.annotations.Test)

Example 4 with UnionNode

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

the class PushProjectionThroughUnion method apply.

@Override
public Result apply(ProjectNode parent, Captures captures, Context context) {
    UnionNode source = captures.get(CHILD);
    // OutputLayout of the resultant Union, will be same as the layout of the Project
    List<Symbol> outputLayout = parent.getOutputSymbols();
    // Mapping from the output symbol to ordered list of symbols from each of the sources
    ImmutableListMultimap.Builder<Symbol, Symbol> mappings = ImmutableListMultimap.builder();
    // sources for the resultant UnionNode
    ImmutableList.Builder<PlanNode> outputSources = ImmutableList.builder();
    for (int i = 0; i < source.getSources().size(); i++) {
        // Map: output of union -> input of this source to the union
        Map<Symbol, SymbolReference> outputToInput = sourceSymbolMap(source, i);
        // assignments for the new ProjectNode
        Assignments.Builder assignments = Assignments.builder();
        // mapping from current ProjectNode to new ProjectNode, used to identify the output layout
        Map<Symbol, Symbol> projectSymbolMapping = new HashMap<>();
        // Translate the assignments in the ProjectNode using symbols of the source of the UnionNode
        for (Map.Entry<Symbol, RowExpression> entry : parent.getAssignments().entrySet()) {
            RowExpression translatedExpression;
            Map<VariableReferenceExpression, VariableReferenceExpression> variable = new HashMap<>();
            Map<Symbol, Type> symbols = context.getSymbolAllocator().getSymbols();
            for (Symbol symbolMap : source.getSymbolMapping().keySet()) {
                Symbol symboli = source.getSymbolMapping().get(symbolMap).get(i);
                variable.put(new VariableReferenceExpression(symbolMap.getName(), symbols.get(symbolMap)), new VariableReferenceExpression(symboli.getName(), symbols.get(symboli)));
            }
            translatedExpression = RowExpressionVariableInliner.inlineVariables(variable, entry.getValue());
            Symbol symbol = context.getSymbolAllocator().newSymbol(translatedExpression);
            assignments.put(symbol, translatedExpression);
            projectSymbolMapping.put(entry.getKey(), symbol);
        }
        outputSources.add(new ProjectNode(context.getIdAllocator().getNextId(), source.getSources().get(i), assignments.build()));
        outputLayout.forEach(symbol -> mappings.put(symbol, projectSymbolMapping.get(symbol)));
    }
    return Result.ofPlanNode(new UnionNode(parent.getId(), outputSources.build(), mappings.build(), ImmutableList.copyOf(mappings.build().keySet())));
}
Also used : HashMap(java.util.HashMap) Symbol(io.prestosql.spi.plan.Symbol) ImmutableList(com.google.common.collect.ImmutableList) SymbolReference(io.prestosql.sql.tree.SymbolReference) Assignments(io.prestosql.spi.plan.Assignments) RowExpression(io.prestosql.spi.relation.RowExpression) Type(io.prestosql.spi.type.Type) PlanNode(io.prestosql.spi.plan.PlanNode) UnionNode(io.prestosql.spi.plan.UnionNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) ProjectNode(io.prestosql.spi.plan.ProjectNode) SetOperationNodeUtils.sourceSymbolMap(io.prestosql.sql.planner.optimizations.SetOperationNodeUtils.sourceSymbolMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with UnionNode

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

the class PushTableWriteThroughUnion method apply.

@Override
public Result apply(TableWriterNode writerNode, Captures captures, Context context) {
    UnionNode unionNode = captures.get(CHILD);
    ImmutableList.Builder<PlanNode> rewrittenSources = ImmutableList.builder();
    List<Map<Symbol, Symbol>> sourceMappings = new ArrayList<>();
    for (int source = 0; source < unionNode.getSources().size(); source++) {
        rewrittenSources.add(rewriteSource(writerNode, unionNode, source, sourceMappings, context));
    }
    ImmutableListMultimap.Builder<Symbol, Symbol> unionMappings = ImmutableListMultimap.builder();
    sourceMappings.forEach(mappings -> mappings.forEach(unionMappings::put));
    return Result.ofPlanNode(new UnionNode(context.getIdAllocator().getNextId(), rewrittenSources.build(), unionMappings.build(), ImmutableList.copyOf(unionMappings.build().keySet())));
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) UnionNode(io.prestosql.spi.plan.UnionNode) ImmutableList(com.google.common.collect.ImmutableList) Symbol(io.prestosql.spi.plan.Symbol) ArrayList(java.util.ArrayList) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Map(java.util.Map)

Aggregations

UnionNode (io.prestosql.spi.plan.UnionNode)11 PlanNode (io.prestosql.spi.plan.PlanNode)10 Symbol (io.prestosql.spi.plan.Symbol)9 ImmutableList (com.google.common.collect.ImmutableList)5 Test (org.testng.annotations.Test)5 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)4 Assignments (io.prestosql.spi.plan.Assignments)3 ProjectNode (io.prestosql.spi.plan.ProjectNode)3 Type (io.prestosql.spi.type.Type)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 CallExpression (io.prestosql.spi.relation.CallExpression)2 RowExpression (io.prestosql.spi.relation.RowExpression)2 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)2 SetOperationNodeUtils.sourceSymbolMap (io.prestosql.sql.planner.optimizations.SetOperationNodeUtils.sourceSymbolMap)2 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)2 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)2 Expression (io.prestosql.sql.tree.Expression)2 Map (java.util.Map)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1