@Override public Expression visitProject(ProjectNode node, Void context) { // TODO: add simple algebraic solver for projection translation (right now only considers // identity projections) Expression underlyingPredicate = node.getSource().accept(this, context); Iterable<Expression> projectionEqualities = transform( filter(node.getOutputMap().entrySet(), not(symbolMatchesExpression())), new Function<Map.Entry<Symbol, Expression>, Expression>() { @Override public Expression apply(Map.Entry<Symbol, Expression> entry) { QualifiedNameReference reference = new QualifiedNameReference(entry.getKey().toQualifiedName()); Expression expression = entry.getValue(); return new ComparisonExpression( ComparisonExpression.Type.EQUAL, reference, expression); } }); return pullExpressionThroughSymbols( combineConjuncts( ImmutableList.<Expression>builder() .addAll(projectionEqualities) .add(underlyingPredicate) .build()), node.getOutputSymbols()); }
@Override public PlanNode visitProject(ProjectNode node, RewriteContext<Set<Symbol>> context) { ImmutableSet.Builder<Symbol> expectedInputs = ImmutableSet.builder(); ImmutableMap.Builder<Symbol, Expression> builder = ImmutableMap.builder(); for (int i = 0; i < node.getOutputSymbols().size(); i++) { Symbol output = node.getOutputSymbols().get(i); Expression expression = node.getAssignments().get(output); if (context.get().contains(output)) { expectedInputs.addAll(DependencyExtractor.extractUnique(expression)); builder.put(output, expression); } } PlanNode source = context.rewrite(node.getSource(), expectedInputs.build()); return new ProjectNode(node.getId(), source, builder.build()); }
@Override public PlanNode visitProject(ProjectNode node, RewriteContext<Void> context) { PlanNode source = context.rewrite(node.getSource()); if (!node.getOutputSymbols().equals(source.getOutputSymbols())) { // Can't get rid of this projection. It constrains the output tuple from the underlying // operator return replaceChildren(node, ImmutableList.of(source)); } if (node.isIdentity()) { return source; } return replaceChildren(node, ImmutableList.of(source)); }
private RelationPlan addConstantSampleWeight(RelationPlan subPlan) { ImmutableMap.Builder<Symbol, Expression> projections = ImmutableMap.builder(); for (Symbol symbol : subPlan.getOutputSymbols()) { Expression expression = new QualifiedNameReference(symbol.toQualifiedName()); projections.put(symbol, expression); } Expression one = new LongLiteral("1"); Symbol sampleWeightSymbol = symbolAllocator.newSymbol("$sampleWeight", BIGINT); projections.put(sampleWeightSymbol, one); ProjectNode projectNode = new ProjectNode(idAllocator.getNextId(), subPlan.getRoot(), projections.build()); return new RelationPlan( projectNode, subPlan.getDescriptor(), projectNode.getOutputSymbols(), Optional.of(sampleWeightSymbol)); }