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);
}
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));
}
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);
}
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())));
}
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())));
}
Aggregations