use of com.facebook.presto.spi.plan.UnionNode in project presto by prestodb.
the class PushTopNThroughUnion method apply.
@Override
public Result apply(TopNNode topNNode, Captures captures, Context context) {
UnionNode unionNode = captures.get(CHILD);
ImmutableList.Builder<PlanNode> sources = ImmutableList.builder();
for (PlanNode source : unionNode.getSources()) {
SymbolMapper.Builder symbolMapper = SymbolMapper.builder();
Set<VariableReferenceExpression> sourceOutputVariables = ImmutableSet.copyOf(source.getOutputVariables());
for (VariableReferenceExpression unionOutput : unionNode.getOutputVariables()) {
Set<VariableReferenceExpression> inputVariables = ImmutableSet.copyOf(unionNode.getVariableMapping().get(unionOutput));
VariableReferenceExpression unionInput = getLast(intersection(inputVariables, sourceOutputVariables));
symbolMapper.put(unionOutput, unionInput);
}
sources.add(symbolMapper.build().map(topNNode, source, context.getIdAllocator().getNextId()));
}
return Result.ofPlanNode(new UnionNode(unionNode.getSourceLocation(), unionNode.getId(), sources.build(), unionNode.getOutputVariables(), unionNode.getVariableMapping()));
}
use of com.facebook.presto.spi.plan.UnionNode in project presto by prestodb.
the class TestTypeValidator method testValidUnion.
@Test
public void testValidUnion() {
VariableReferenceExpression output = variableAllocator.newVariable("output", DATE);
PlanNode node = new UnionNode(Optional.empty(), newId(), ImmutableList.of(baseTableScan, baseTableScan), ImmutableList.of(output), ImmutableMap.of(output, ImmutableList.of(variableD, variableD)));
assertTypesValid(node);
}
use of com.facebook.presto.spi.plan.UnionNode in project presto by prestodb.
the class TestTypeValidator method testInvalidUnion.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of variable 'output(_[0-9]+)?' is expected to be date, but the actual type is bigint")
public void testInvalidUnion() {
VariableReferenceExpression output = variableAllocator.newVariable("output", DATE);
PlanNode node = new UnionNode(Optional.empty(), newId(), ImmutableList.of(baseTableScan, baseTableScan), ImmutableList.of(output), ImmutableMap.of(output, ImmutableList.of(variableD, // should be a symbol with DATE type
variableA)));
assertTypesValid(node);
}
use of com.facebook.presto.spi.plan.UnionNode in project presto by prestodb.
the class TestEffectivePredicateExtractor method testUnion.
@Test
public void testUnion() {
PlanNode node = new UnionNode(Optional.empty(), newId(), ImmutableList.of(filter(baseTableScan, greaterThan(AV, bigintLiteral(10))), filter(baseTableScan, and(greaterThan(AV, bigintLiteral(10)), lessThan(AV, bigintLiteral(100)))), filter(baseTableScan, and(greaterThan(AV, bigintLiteral(10)), lessThan(AV, bigintLiteral(100))))), ImmutableList.of(AV), ImmutableMap.of(AV, ImmutableList.of(BV, CV, EV)));
RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
// Only the common conjuncts can be inferred through a Union
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(greaterThan(AV, bigintLiteral(10))));
}
use of com.facebook.presto.spi.plan.UnionNode in project presto by prestodb.
the class TestDruidPlanOptimizer method testUnionAll.
@Test
public void testUnionAll() {
PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
PlanVariableAllocator variableAllocator = new PlanVariableAllocator();
AggregationNode aggregationOne = simpleAggregationSum(planBuilder, tableScan(planBuilder, druidTableOne, city, fare), variableAllocator, ImmutableList.of(city), fare);
AggregationNode aggregationTwo = simpleAggregationSum(planBuilder, tableScan(planBuilder, druidTableTwo, city, fare), variableAllocator, ImmutableList.of(city), fare);
VariableReferenceExpression groupByColumn = variableAllocator.newVariable(city.getColumnName(), city.getColumnType());
VariableReferenceExpression sumColumn = variableAllocator.newVariable(fare.getColumnName(), fare.getColumnType());
PlanNode originalPlan = new UnionNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), ImmutableList.of(aggregationOne, aggregationTwo), ImmutableList.of(groupByColumn, sumColumn), ImmutableMap.of(groupByColumn, Stream.concat(aggregationOne.getGroupingKeys().stream(), aggregationTwo.getGroupingKeys().stream()).collect(toImmutableList()), sumColumn, ImmutableList.of(Iterables.getOnlyElement(aggregationOne.getAggregations().keySet()), Iterables.getOnlyElement(aggregationTwo.getAggregations().keySet()))));
PlanNode optimizedPlan = getOptimizedPlan(planBuilder, originalPlan);
PlanMatchPattern tableScanMatcherOne = DruidTableScanMatcher.match(druidTableOne.getTableName(), "SELECT \"city\", sum(fare) FROM \"realtimeOnly\" GROUP BY \"city\"");
PlanMatchPattern tableScanMatcherTwo = DruidTableScanMatcher.match(druidTableTwo.getTableName(), "SELECT \"city\", sum(fare) FROM \"hybrid\" GROUP BY \"city\"");
assertPlanMatch(optimizedPlan, PlanMatchPattern.union(tableScanMatcherOne, tableScanMatcherTwo), typeProvider);
}
Aggregations