use of io.prestosql.expressions.RowExpressionRewriter in project hetu-core by openlookeng.
the class CubeOptimizer method rewriteJoinNode.
private JoinNode rewriteJoinNode(JoinNode original, PlanNode rewrittenLeftChild, PlanNode rewrittenRightChild) {
List<Symbol> joinOutputSymbols = new ArrayList<>(rewrittenLeftChild.getOutputSymbols());
joinOutputSymbols.addAll(rewrittenRightChild.getOutputSymbols());
List<JoinNode.EquiJoinClause> rewrittenJoinCriteria = new ArrayList<>();
for (JoinNode.EquiJoinClause criteria : original.getCriteria()) {
Symbol rewrittenLeft = optimizedPlanMappings.get(columnRewritesMap.get(criteria.getLeft().getName()));
Symbol rewrittenRight = optimizedPlanMappings.get(columnRewritesMap.get(criteria.getRight().getName()));
rewrittenJoinCriteria.add(new JoinNode.EquiJoinClause(rewrittenLeft, rewrittenRight));
}
Optional<Symbol> leftHashSymbol = original.getLeftHashSymbol().map(Symbol::getName).map(columnRewritesMap::get).map(optimizedPlanMappings::get);
Optional<Symbol> rightHashSymbol = original.getRightHashSymbol().map(Symbol::getName).map(columnRewritesMap::get).map(optimizedPlanMappings::get);
Optional<RowExpression> rewrittenJoinFilter = original.getFilter().map(rowExpression -> RowExpressionTreeRewriter.rewriteWith(new RowExpressionRewriter<Void>() {
@Override
public RowExpression rewriteVariableReference(VariableReferenceExpression variable, Void context, RowExpressionTreeRewriter<Void> treeRewriter) {
return new VariableReferenceExpression(optimizedPlanMappings.get(columnRewritesMap.get(variable.getName())).getName(), variable.getType());
}
}, rowExpression));
Map<String, Symbol> rewrittenDynamicFilters = original.getDynamicFilters().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> optimizedPlanMappings.get(columnRewritesMap.get(entry.getValue().getName()))));
return new JoinNode(context.getIdAllocator().getNextId(), original.getType(), rewrittenLeftChild, rewrittenRightChild, rewrittenJoinCriteria, joinOutputSymbols, rewrittenJoinFilter, leftHashSymbol, rightHashSymbol, original.getDistributionType(), original.isSpillable(), rewrittenDynamicFilters);
}
Aggregations