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(); }
private void map(Symbol symbol, Symbol canonical) { Preconditions.checkArgument(!symbol.equals(canonical), "Can't map symbol to itself: %s", symbol); mapping.put(symbol, canonical); }
@Override public Expression rewriteSymbolReference(SymbolReference node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { Symbol canonical = canonicalize(Symbol.from(node)); return canonical.toSymbolReference(); } }, value);
public Expression toPredicate(TupleDomain<Symbol> tupleDomain) { if (tupleDomain.isNone()) { return FALSE_LITERAL; } Map<Symbol, Domain> domains = tupleDomain.getDomains().get(); return domains.entrySet().stream() .sorted(comparing(entry -> entry.getKey().getName())) .map(entry -> toPredicate(entry.getValue(), entry.getKey().toSymbolReference())) .collect(collectingAndThen(toImmutableList(), ExpressionUtils::combineConjuncts)); }
FunctionCall functionCall = entry.getValue().getCall(); if (!entry.getValue().getMask().isPresent()) { Symbol newSymbol = symbolAllocator.newSymbol(entry.getKey().toSymbolReference(), symbolAllocator.getTypes().get(entry.getKey())); aggregationOutputSymbolsMapBuilder.put(newSymbol, entry.getKey()); if (!duplicatedDistinctSymbol.equals(distinctSymbol)) { if (functionCall.getArguments().contains(distinctSymbol.toSymbolReference())) { ImmutableList.Builder<Expression> arguments = ImmutableList.builder(); for (Expression argument : functionCall.getArguments()) { if (distinctSymbol.toSymbolReference().equals(argument)) { arguments.add(duplicatedDistinctSymbol.toSymbolReference());
@Override protected Void visitSymbolReference(SymbolReference node, ImmutableList.Builder<Symbol> builder) { builder.add(Symbol.from(node)); return null; } }
@Override public Object getValue(Symbol symbol) { return symbol.toSymbolReference(); } }
@Override public Void visitOutput(OutputNode node, Integer indent) { print(indent, "- Output[%s] => [%s]", Joiner.on(", ").join(node.getColumnNames()), formatOutputs(node.getOutputSymbols())); printPlanNodesStatsAndCost(indent + 2, node); printStats(indent + 2, node.getId()); for (int i = 0; i < node.getColumnNames().size(); i++) { String name = node.getColumnNames().get(i); Symbol symbol = node.getOutputSymbols().get(i); if (!name.equals(symbol.toString())) { print(indent + 2, "%s := %s", name, symbol); } } return processChildren(node, indent + 1); }
ImmutableMap.Builder<Symbol, Symbol> outputNonDistinctAggregateSymbols = ImmutableMap.builder(); for (Symbol symbol : source.getOutputSymbols()) { if (distinctSymbol.equals(symbol)) { Symbol newSymbol = symbolAllocator.newSymbol("expr", symbolAllocator.getTypes().get(symbol)); aggregateInfo.setNewDistinctAggregateSymbol(newSymbol); groupSymbol.toSymbolReference(), new Cast(new LongLiteral("1"), "bigint"), // TODO: this should use GROUPING() when that's available instead of relying on specific group numbering ComparisonExpression.Operator.EQUAL, symbol.toSymbolReference(), symbolAllocator.getTypes().get(symbol)); outputSymbols.put(newSymbol, expression); groupSymbol.toSymbolReference(), new Cast(new LongLiteral("0"), "bigint"), // TODO: this should use GROUPING() when that's available instead of relying on specific group numbering ComparisonExpression.Operator.EQUAL, symbol.toSymbolReference(), symbolAllocator.getTypes().get(symbol)); outputSymbols.put(newSymbol, expression); Expression expression = symbol.toSymbolReference(); outputSymbols.put(symbol, expression);
private static Map<Symbol, Symbol> computeIdentityTranslations(Map<Symbol, Expression> assignments) { Map<Symbol, Symbol> inputToOutput = new HashMap<>(); for (Map.Entry<Symbol, Expression> assignment : assignments.entrySet()) { if (assignment.getValue() instanceof SymbolReference) { inputToOutput.put(Symbol.from(assignment.getValue()), assignment.getKey()); } } return inputToOutput; } }
/** * Returns the output to input symbol mapping for the given source channel */ public Map<Symbol, SymbolReference> sourceSymbolMap(int sourceIndex) { ImmutableMap.Builder<Symbol, SymbolReference> builder = ImmutableMap.builder(); for (Map.Entry<Symbol, Collection<Symbol>> entry : outputToInputs.asMap().entrySet()) { builder.put(entry.getKey(), Iterables.get(entry.getValue(), sourceIndex).toSymbolReference()); } return builder.build(); }
static boolean orderingSchemeMatches(List<Ordering> expectedOrderBy, OrderingScheme orderingScheme, SymbolAliases symbolAliases) { if (expectedOrderBy.size() != orderingScheme.getOrderBy().size()) { return false; } for (int i = 0; i < expectedOrderBy.size(); ++i) { Ordering ordering = expectedOrderBy.get(i); Symbol symbol = Symbol.from(symbolAliases.get(ordering.getField())); if (!symbol.equals(orderingScheme.getOrderBy().get(i))) { return false; } if (!ordering.getSortOrder().equals(orderingScheme.getOrdering(symbol))) { return false; } } return true; } }
@Override public Expression rewriteSymbolReference(SymbolReference node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { Symbol canonical = map(Symbol.from(node)); return canonical.toSymbolReference(); } }, value);
public static Symbol from(Expression expression) { checkArgument(expression instanceof SymbolReference, "Unexpected expression: %s", expression); return new Symbol(((SymbolReference) expression).getName()); }
public Symbol newSymbol(Symbol symbolHint) { checkArgument(symbols.containsKey(symbolHint), "symbolHint not in symbols map"); return newSymbol(symbolHint.getName(), symbols.get(symbolHint)); }
public Symbol map(Symbol symbol) { Symbol canonical = symbol; while (mapping.containsKey(canonical) && !mapping.get(canonical).equals(canonical)) { canonical = mapping.get(canonical); } return canonical; }
Symbol output = exchange.getOutputSymbols().get(outputIndex); Symbol input = exchange.getInputs().get(i).get(outputIndex); if (!output.equals(input)) { mappingsBuilder.put(output, input); assignments.put(output, input.toSymbolReference());
private static Map<Symbol, Symbol> computeIdentityTranslations(Map<Symbol, Expression> assignments) { Map<Symbol, Symbol> inputToOutput = new HashMap<>(); for (Map.Entry<Symbol, Expression> assignment : assignments.entrySet()) { if (assignment.getValue() instanceof SymbolReference) { inputToOutput.put(Symbol.from(assignment.getValue()), assignment.getKey()); } } return inputToOutput; }