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 protected Void visitSymbolReference(SymbolReference node, ImmutableList.Builder<Symbol> builder) { builder.add(Symbol.from(node)); return null; } }
@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)); }
@Override public Object getValue(Symbol symbol) { return symbol.toSymbolReference(); } }
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 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); }
private static int comparePartitionBy(WindowNode o1, WindowNode o2) { Iterator<Symbol> iterator1 = o1.getPartitionBy().iterator(); Iterator<Symbol> iterator2 = o2.getPartitionBy().iterator(); while (iterator1.hasNext() && iterator2.hasNext()) { Symbol symbol1 = iterator1.next(); Symbol symbol2 = iterator2.next(); int partitionByComparison = symbol1.compareTo(symbol2); if (partitionByComparison != 0) { return partitionByComparison; } } if (iterator1.hasNext()) { return 1; } if (iterator2.hasNext()) { return -1; } return 0; }
public boolean isIdentity(Symbol output) { Expression expression = assignments.get(output); return expression instanceof SymbolReference && ((SymbolReference) expression).getName().equals(output.getName()); }
@Override public Object getValue(Symbol symbol) { return symbol.toSymbolReference(); } }
@Override public Expression rewriteSymbolReference(SymbolReference node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { Symbol canonical = map(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)); }
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 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); }
private static int comparePartitionBy(WindowNode o1, WindowNode o2) { Iterator<Symbol> iterator1 = o1.getPartitionBy().iterator(); Iterator<Symbol> iterator2 = o2.getPartitionBy().iterator(); while (iterator1.hasNext() && iterator2.hasNext()) { Symbol symbol1 = iterator1.next(); Symbol symbol2 = iterator2.next(); int partitionByComparison = symbol1.compareTo(symbol2); if (partitionByComparison != 0) { return partitionByComparison; } } if (iterator1.hasNext()) { return 1; } if (iterator2.hasNext()) { return -1; } return 0; }
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); }
public Symbol newSymbol(Symbol symbolHint) { checkArgument(symbols.containsKey(symbolHint), "symbolHint not in symbols map"); return newSymbol(symbolHint.getName(), symbols.get(symbolHint)); }