public boolean isIdentity(Symbol output) { Expression expression = assignments.get(output); return expression instanceof SymbolReference && ((SymbolReference) expression).getName().equals(output.getName()); }
public Symbol newSymbol(Symbol symbolHint) { checkArgument(symbols.containsKey(symbolHint), "symbolHint not in symbols map"); return newSymbol(symbolHint.getName(), symbols.get(symbolHint)); }
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()); } }
public boolean isIdentity() { for (Map.Entry<Symbol, Expression> entry : assignments.entrySet()) { Expression expression = entry.getValue(); Symbol symbol = entry.getKey(); if (!(expression instanceof SymbolReference && ((SymbolReference) expression).getName().equals(symbol.getName()))) { return false; } } return true; }
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)); }
private static Predicate<Symbol> symbolBeginsWith(final Iterable<String> prefixes) { return symbol -> { for (String prefix : prefixes) { if (symbol.getName().startsWith(prefix)) { return true; } } return false; }; }
public OutputBuilder column(Symbol symbol) { return column(symbol, symbol.getName()); }
@Override public Expression rewriteLambdaExpression(LambdaExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { checkState(analysis.getCoercion(node) == null, "cannot coerce a lambda expression"); ImmutableList.Builder<LambdaArgumentDeclaration> newArguments = ImmutableList.builder(); for (LambdaArgumentDeclaration argument : node.getArguments()) { Symbol symbol = lambdaDeclarationToSymbolMap.get(NodeRef.of(argument)); newArguments.add(new LambdaArgumentDeclaration(new Identifier(symbol.getName()))); } Expression rewrittenBody = treeRewriter.rewrite(node.getBody(), null); return new LambdaExpression(newArguments.build(), rewrittenBody); }
private static Type generateType(Symbol symbol) { String typeName = Splitter.on('_').limit(2).splitToList(symbol.getName()).get(1); return METADATA.getType(new TypeSignature(typeName, ImmutableList.of())); } }
@Test public void testUsedInputsNotNeeded() { // If the WindowNode needs all its inputs, we can't discard them from its child. tester().assertThat(new PruneWindowColumns()) .on(p -> buildProjectedWindow( p, // only the window function outputs symbol -> !inputSymbolNameSet.contains(symbol.getName()), // only the used input symbols symbol -> !symbol.getName().equals("unused"))) .doesNotFire(); }
private void assertSymbolStatsEqual(Symbol symbol, SymbolStatsEstimate actual, SymbolStatsEstimate expected) { assertEstimateEquals(actual.getNullsFraction(), expected.getNullsFraction(), "nullsFraction mismatch for %s", symbol.getName()); assertEstimateEquals(actual.getLowValue(), expected.getLowValue(), "lowValue mismatch for %s", symbol.getName()); assertEstimateEquals(actual.getHighValue(), expected.getHighValue(), "highValue mismatch for %s", symbol.getName()); assertEstimateEquals(actual.getDistinctValuesCount(), expected.getDistinctValuesCount(), "distinct values count mismatch for %s", symbol.getName()); assertEstimateEquals(actual.getAverageRowSize(), expected.getAverageRowSize(), "average row size mismatch for %s", symbol.getName()); } }
@Test public void testAllColumnsNeeded() { tester().assertThat(new PruneSemiJoinFilteringSourceColumns()) .on(p -> buildSemiJoin(p, symbol -> !symbol.getName().equals("rightValue"))) .doesNotFire(); }
@Test public void testAllInputsRereferenced() { tester().assertThat(new PruneTopNColumns()) .on(p -> buildProjectedTopN(p, symbol -> symbol.getName().equals("a"))) .doesNotFire(); }
@Test public void testAllInputsReferenced() { tester().assertThat(new PruneAggregationSourceColumns()) .on(p -> buildAggregation(p, symbol -> !symbol.getName().equals("unused"))) .doesNotFire(); }
@Test public void testAllInputsReferenced() { tester().assertThat(new PruneFilterColumns()) .on(p -> buildProjectedFilter(p, symbol -> symbol.getName().equals("a"))) .doesNotFire(); }
@Test public void testSemiJoinNotNeeded() { tester().assertThat(new PruneSemiJoinColumns()) .on(p -> buildProjectedSemiJoin(p, symbol -> symbol.getName().equals("leftValue"))) .matches( strictProject( ImmutableMap.of("leftValue", expression("leftValue")), values("leftKey", "leftKeyHash", "leftValue"))); }
@Test public void testWindowNotNeeded() { tester().assertThat(new PruneWindowColumns()) .on(p -> buildProjectedWindow(p, symbol -> inputSymbolNameSet.contains(symbol.getName()), alwaysTrue())) .matches( strictProject( Maps.asMap(inputSymbolNameSet, PlanMatchPattern::expression), values(inputSymbolNameList))); }
@Test public void testNotAllInputsReferenced() { tester().assertThat(new PruneLimitColumns()) .on(p -> buildProjectedLimit(p, symbol -> symbol.getName().equals("b"))) .matches( strictProject( ImmutableMap.of("b", expression("b")), limit( 1, strictProject( ImmutableMap.of("b", expression("b")), values("a", "b"))))); }