@Override protected Boolean visitSymbolReference(SymbolReference symbolReference, Void context) { return buildSymbols.contains(symbolReference.getName()); } }
public SymbolReference toSymbolReference() { return new SymbolReference(name); }
public Builder put(String alias, SymbolReference symbolReference) { requireNonNull(alias, "alias is null"); requireNonNull(symbolReference, "symbolReference is null"); alias = toKey(alias); // Special case to allow identity binding (i.e. "ALIAS" -> expression("ALIAS")) if (bindings.containsKey(alias) && bindings.get(alias).equals(symbolReference)) { return this; } checkState(!bindings.containsKey(alias), "Alias '%s' already bound to expression '%s'. Tried to rebind to '%s'", alias, bindings.get(alias), symbolReference); bindings.put(alias, symbolReference); return this; }
ImmutableList.Builder<Expression> arguments = ImmutableList.builder(); for (Expression argument : functionCall.getArguments()) { if (distinctSymbol.toSymbolReference().equals(argument)) { arguments.add(duplicatedDistinctSymbol.toSymbolReference());
@Override public Expression rewriteSymbolReference(SymbolReference node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { if (excludedNames.contains(node.getName())) { return node; } Expression expression = mapping.apply(Symbol.from(node)); checkState(expression != null, "Cannot resolve symbol %s", node.getName()); return expression; }
@Override public Expression rewriteIdentifier(Identifier node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { return new SymbolReference(node.getValue()); }
private Map<String, SymbolReference> getUpdatedAssignments(Assignments assignments) { ImmutableMap.Builder<String, SymbolReference> mapUpdate = ImmutableMap.builder(); for (Map.Entry<Symbol, Expression> assignment : assignments.getMap().entrySet()) { for (Map.Entry<String, SymbolReference> existingAlias : map.entrySet()) { if (assignment.getValue().equals(existingAlias.getValue())) { // Simple symbol rename mapUpdate.put(existingAlias.getKey(), assignment.getKey().toSymbolReference()); } else if (assignment.getKey().toSymbolReference().equals(existingAlias.getValue())) { /* * Special case for nodes that can alias symbols in the node's assignment map. * In this case, we've already added the alias in the map, but we won't include it * as a simple rename as covered above. Add the existing alias to the result if * the LHS of the assignment matches the symbol reference of the existing alias. * * This comes up when we alias expressions in project nodes for use further up the tree. * At the beginning for the function, map contains { NEW_ALIAS: SymbolReference("expr_2" } * and the assignments map contains { expr_2 := <some expression> }. */ mapUpdate.put(existingAlias.getKey(), existingAlias.getValue()); } } } return mapUpdate.build(); }
public boolean isIdentity(Symbol output) { Expression expression = assignments.get(output); return expression instanceof SymbolReference && ((SymbolReference) expression).getName().equals(output.getName()); }
private static SymbolReference nameReference(String symbol) { return new SymbolReference(symbol); }
@Override public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) { checkState( shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName()); List<Symbol> actualCorrelation = getCorrelation(node); if (this.correlation.size() != actualCorrelation.size()) { return NO_MATCH; } int i = 0; for (String alias : this.correlation) { if (!symbolAliases.get(alias).equals(actualCorrelation.get(i++).toSymbolReference())) { return NO_MATCH; } } return match(); }
private static Optional<SymbolReference> asBuildSymbolReference(Set<Symbol> buildLayout, Expression expression) { // Currently only we support only symbol as sort expression on build side if (expression instanceof SymbolReference) { SymbolReference symbolReference = (SymbolReference) expression; if (buildLayout.contains(new Symbol(symbolReference.getName()))) { return Optional.of(symbolReference); } } return Optional.empty(); }
public static Optional<Expression> getHashExpression(List<Symbol> symbols) { if (symbols.isEmpty()) { return Optional.empty(); } Expression result = new LongLiteral(String.valueOf(INITIAL_HASH_VALUE)); for (Symbol symbol : symbols) { Expression hashField = new FunctionCall( QualifiedName.of(HASH_CODE), Optional.empty(), false, ImmutableList.of(new SymbolReference(symbol.getName()))); hashField = new CoalesceExpression(hashField, new LongLiteral(String.valueOf(NULL_HASH_CODE))); result = new FunctionCall(QualifiedName.of("combine_hash"), ImmutableList.of(result, hashField)); } return Optional.of(result); }
@Override public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) { checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName()); SemiJoinNode semiJoinNode = (SemiJoinNode) node; if (!(symbolAliases.get(sourceSymbolAlias).equals(semiJoinNode.getSourceJoinSymbol().toSymbolReference()) && symbolAliases.get(filteringSymbolAlias).equals(semiJoinNode.getFilteringSourceJoinSymbol().toSymbolReference()))) { return NO_MATCH; } if (distributionType.isPresent() && !distributionType.equals(semiJoinNode.getDistributionType())) { return NO_MATCH; } return match(outputAlias, semiJoinNode.getSemiJoinOutput().toSymbolReference()); }
@Override protected String visitSymbolReference(SymbolReference node, Void context) { return formatIdentifier(node.getName()); }
private static void assertGetSortExpression(Expression expression, String expectedSymbol, List<Expression> searchExpressions) { Optional<SortExpressionContext> expected = Optional.of(new SortExpressionContext(new SymbolReference(expectedSymbol), searchExpressions)); Optional<SortExpressionContext> actual = SortExpressionExtractor.extractSortExpression(BUILD_SYMBOLS, expression); assertEquals(actual, expected); } }
public static Symbol from(Expression expression) { checkArgument(expression instanceof SymbolReference, "Unexpected expression: %s", expression); return new Symbol(((SymbolReference) expression).getName()); }
.map(symbol -> new SymbolReference(symbol.getName())) .collect(toImmutableList()); rewrittenExpression = new BindExpression(capturedValues, rewrittenExpression);
private void printAssignments(Assignments assignments, int indent) { for (Map.Entry<Symbol, Expression> entry : assignments.getMap().entrySet()) { if (entry.getValue() instanceof SymbolReference && ((SymbolReference) entry.getValue()).getName().equals(entry.getKey().getName())) { // skip identity assignments continue; } print(indent, "%s := %s", entry.getKey(), entry.getValue()); } }
@Test public void dependentWindowsAreNotReordered() { Optional<Window> windowA = Optional.of(new Window(ImmutableList.of(new SymbolReference("a")), Optional.empty(), Optional.empty())); tester().assertThat(new GatherAndMergeWindows.SwapAdjacentWindowsBySpecifications(0)) .on(p -> p.window(new WindowNode.Specification( ImmutableList.of(p.symbol("a")), Optional.empty()), ImmutableMap.of(p.symbol("avg_1"), new WindowNode.Function(new FunctionCall(QualifiedName.of("avg"), windowA, false, ImmutableList.of(new SymbolReference("avg_2"))), signature, frame)), p.window(new WindowNode.Specification( ImmutableList.of(p.symbol("a"), p.symbol("b")), Optional.empty()), ImmutableMap.of(p.symbol("avg_2"), new WindowNode.Function(new FunctionCall(QualifiedName.of("avg"), windowA, false, ImmutableList.of(new SymbolReference("a"))), signature, frame)), p.values(p.symbol("a"), p.symbol("b"))))) .doesNotFire(); } }