use of io.prestosql.spi.plan.UnionNode in project hetu-core by openlookeng.
the class PushLimitThroughUnion method apply.
@Override
public Result apply(LimitNode parent, Captures captures, Context context) {
UnionNode unionNode = captures.get(CHILD);
ImmutableList.Builder<PlanNode> builder = ImmutableList.builder();
boolean shouldApply = false;
for (PlanNode source : unionNode.getSources()) {
// This check is to ensure that we don't fire the optimizer if it was previously applied.
if (isAtMost(source, context.getLookup(), parent.getCount())) {
builder.add(source);
} else {
shouldApply = true;
builder.add(new LimitNode(context.getIdAllocator().getNextId(), source, parent.getCount(), true));
}
}
if (!shouldApply) {
return Result.empty();
}
return Result.ofPlanNode(parent.replaceChildren(ImmutableList.of(unionNode.replaceChildren(builder.build()))));
}
use of io.prestosql.spi.plan.UnionNode in project hetu-core by openlookeng.
the class SetOperationNodeTranslator method makeSetContainmentPlan.
public TranslationResult makeSetContainmentPlan(SetOperationNode node) {
checkArgument(!(node instanceof UnionNode), "Cannot simplify a UnionNode");
List<Symbol> markers = allocateSymbols(node.getSources().size(), MARKER, BOOLEAN);
// identity projection for all the fields in each of the sources plus marker columns
List<PlanNode> withMarkers = appendMarkers(markers, node.getSources(), node);
// add a union over all the rewritten sources. The outputs of the union have the same name as the
// original intersect node
List<Symbol> outputs = node.getOutputSymbols();
UnionNode union = union(withMarkers, ImmutableList.copyOf(concat(outputs, markers)));
// add count aggregations and filter rows where any of the counts is >= 1
List<Symbol> aggregationOutputs = allocateSymbols(markers.size(), "count", BIGINT);
AggregationNode aggregation = computeCounts(union, outputs, markers, aggregationOutputs);
List<Expression> presentExpression = aggregationOutputs.stream().map(symbol -> new ComparisonExpression(GREATER_THAN_OR_EQUAL, toSymbolReference(symbol), GENERIC_LITERAL)).collect(toImmutableList());
return new TranslationResult(aggregation, presentExpression);
}
use of io.prestosql.spi.plan.UnionNode in project hetu-core by openlookeng.
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<Symbol> sourceOutputSymbols = ImmutableSet.copyOf(source.getOutputSymbols());
for (Symbol unionOutput : unionNode.getOutputSymbols()) {
Set<Symbol> inputSymbols = ImmutableSet.copyOf(unionNode.getSymbolMapping().get(unionOutput));
Symbol unionInput = getLast(intersection(inputSymbols, sourceOutputSymbols));
symbolMapper.put(unionOutput, unionInput);
}
sources.add(symbolMapper.build().map(topNNode, source, context.getIdAllocator().getNextId()));
}
return Result.ofPlanNode(new UnionNode(unionNode.getId(), sources.build(), unionNode.getSymbolMapping(), unionNode.getOutputSymbols()));
}
use of io.prestosql.spi.plan.UnionNode in project hetu-core by openlookeng.
the class RelationPlanner method visitUnion.
@Override
protected RelationPlan visitUnion(Union node, Void context) {
checkArgument(!node.getRelations().isEmpty(), "No relations specified for UNION");
SetOperationPlan setOperationPlan = process(node);
PlanNode planNode = new UnionNode(idAllocator.getNextId(), setOperationPlan.getSources(), setOperationPlan.getSymbolMapping(), ImmutableList.copyOf(setOperationPlan.getSymbolMapping().keySet()));
if (node.isDistinct()) {
planNode = distinct(planNode);
}
return new RelationPlan(planNode, analysis.getScope(node), planNode.getOutputSymbols());
}
use of io.prestosql.spi.plan.UnionNode in project hetu-core by openlookeng.
the class TestEffectivePredicateExtractor method testUnion.
@Test
public void testUnion() {
ImmutableListMultimap<Symbol, Symbol> symbolMapping = ImmutableListMultimap.of(A, B, A, C, A, E);
PlanNode node = new UnionNode(newId(), ImmutableList.of(filter(baseTableScan, greaterThan(AE, bigintLiteral(10))), filter(baseTableScan, and(greaterThan(AE, bigintLiteral(10)), lessThan(AE, bigintLiteral(100)))), filter(baseTableScan, and(greaterThan(AE, bigintLiteral(10)), lessThan(AE, bigintLiteral(100))))), symbolMapping, ImmutableList.copyOf(symbolMapping.keySet()));
Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
// Only the common conjuncts can be inferred through a Union
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(greaterThan(AE, bigintLiteral(10))));
}
Aggregations