use of io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode in project hetu-core by openlookeng.
the class TransformCorrelatedLateralJoinToJoin method apply.
@Override
public Result apply(LateralJoinNode lateralJoinNode, Captures captures, Context context) {
PlanNode subquery = lateralJoinNode.getSubquery();
PlanNodeDecorrelator planNodeDecorrelator = new PlanNodeDecorrelator(context.getIdAllocator(), context.getLookup());
Optional<DecorrelatedNode> decorrelatedNodeOptional = planNodeDecorrelator.decorrelateFilters(subquery, lateralJoinNode.getCorrelation());
return decorrelatedNodeOptional.map(decorrelatedNode -> {
Expression joinFilter = combineConjuncts(decorrelatedNode.getCorrelatedPredicates().orElse(TRUE_LITERAL), lateralJoinNode.getFilter());
return Result.ofPlanNode(new JoinNode(context.getIdAllocator().getNextId(), lateralJoinNode.getType().toJoinNodeType(), lateralJoinNode.getInput(), decorrelatedNode.getNode(), ImmutableList.of(), lateralJoinNode.getOutputSymbols(), joinFilter.equals(TRUE_LITERAL) ? Optional.empty() : Optional.of(castToRowExpression(joinFilter)), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of()));
}).orElseGet(Result::empty);
}
use of io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode in project hetu-core by openlookeng.
the class ScalarAggregationToJoinRewriter method rewriteScalarAggregation.
public PlanNode rewriteScalarAggregation(LateralJoinNode lateralJoinNode, AggregationNode aggregation) {
List<Symbol> correlation = lateralJoinNode.getCorrelation();
Optional<DecorrelatedNode> source = planNodeDecorrelator.decorrelateFilters(lookup.resolve(aggregation.getSource()), correlation);
if (!source.isPresent()) {
return lateralJoinNode;
}
Symbol nonNull = planSymbolAllocator.newSymbol("non_null", BooleanType.BOOLEAN);
Assignments scalarAggregationSourceAssignments = Assignments.builder().putAll(AssignmentUtils.identityAsSymbolReferences(source.get().getNode().getOutputSymbols())).put(nonNull, castToRowExpression(TRUE_LITERAL)).build();
ProjectNode scalarAggregationSourceWithNonNullableSymbol = new ProjectNode(idAllocator.getNextId(), source.get().getNode(), scalarAggregationSourceAssignments);
return rewriteScalarAggregation(lateralJoinNode, aggregation, scalarAggregationSourceWithNonNullableSymbol, source.get().getCorrelatedPredicates(), nonNull);
}
Aggregations