@Override public Object getValue(Symbol symbol) { return symbol.toSymbolReference(); } }
/** * 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(); }
public Builder putIdentity(Symbol symbol) { put(symbol, symbol.toSymbolReference()); return this; }
@Override public Expression rewriteExpression(Expression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { if (expressionToSymbols.containsKey(node)) { return expressionToSymbols.get(node).toSymbolReference(); } Expression translated = expressionToExpressions.getOrDefault(node, node); return treeRewriter.defaultRewrite(translated, context); } }, mapped);
private Expression inlineReferences(Expression expression, Assignments assignments) { Function<Symbol, Expression> mapping = symbol -> { Expression result = assignments.get(symbol); if (result != null) { return result; } return symbol.toSymbolReference(); }; return inlineSymbols(mapping, expression); }
private Expression rewriteExpressionWithResolvedName(Expression node) { return getSymbol(rewriteBase, node) .map(symbol -> coerceIfNecessary(node, symbol.toSymbolReference())) .orElse(coerceIfNecessary(node, node)); }
private static Expression isGreaterThan(Symbol symbol, long value) { return new ComparisonExpression( ComparisonExpression.Operator.GREATER_THAN, symbol.toSymbolReference(), bigint(value)); }
@Override public Expression rewriteSymbolReference(SymbolReference node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { Symbol canonical = map(Symbol.from(node)); return canonical.toSymbolReference(); } }, value);
public ArgumentBinding translate(Function<Symbol, Symbol> translator) { if (isConstant()) { return this; } return expressionBinding(translator.apply(Symbol.from(expression)).toSymbolReference()); }
@Override public Expression rewriteFieldReference(FieldReference node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { Symbol symbol = rewriteBase.getSymbol(node.getFieldIndex()); checkState(symbol != null, "No symbol mapping for node '%s' (%s)", node, node.getFieldIndex()); return symbol.toSymbolReference(); }
private static Expression getHashFunctionCall(Expression previousHashValue, Symbol symbol) { FunctionCall functionCall = new FunctionCall( QualifiedName.of(HASH_CODE), Optional.empty(), false, ImmutableList.of(symbol.toSymbolReference())); List<Expression> arguments = ImmutableList.of(previousHashValue, orNullHashCode(functionCall)); return new FunctionCall(QualifiedName.of("combine_hash"), arguments); }
private static boolean isSemiJoinOutputReference(Expression conjunct, Symbol semiJoinOutput) { SymbolReference semiJoinOuputSymbolReference = semiJoinOutput.toSymbolReference(); return conjunct.equals(semiJoinOuputSymbolReference) || (conjunct instanceof NotExpression && ((NotExpression) conjunct).getValue().equals(semiJoinOuputSymbolReference)); }
@Override public Expression rewriteIdentifier(Identifier node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { LambdaArgumentDeclaration referencedLambdaArgumentDeclaration = analysis.getLambdaArgumentReference(node); if (referencedLambdaArgumentDeclaration != null) { Symbol symbol = lambdaDeclarationToSymbolMap.get(NodeRef.of(referencedLambdaArgumentDeclaration)); return coerceIfNecessary(node, symbol.toSymbolReference()); } else { return rewriteExpressionWithResolvedName(node); } }
private FilterNode addFilterForIntersect(AggregationNode aggregation) { ImmutableList<Expression> predicates = aggregation.getAggregations().keySet().stream() .map(column -> new ComparisonExpression(GREATER_THAN_OR_EQUAL, column.toSymbolReference(), new GenericLiteral("BIGINT", "1"))) .collect(toImmutableList()); return new FilterNode(idAllocator.getNextId(), aggregation, ExpressionUtils.and(predicates)); }
@Override public PlanNode visitSemiJoin(SemiJoinNode node, RewriteContext<Expression> context) { Expression inheritedPredicate = context.get(); if (!extractConjuncts(inheritedPredicate).contains(node.getSemiJoinOutput().toSymbolReference())) { return visitNonFilteringSemiJoin(node, context); } return visitFilteringSemiJoin(node, context); }
public static List<Expression> toSymbolReferences(List<PlanTestSymbol> aliases, SymbolAliases symbolAliases) { return aliases .stream() .map(arg -> arg.toSymbol(symbolAliases).toSymbolReference()) .collect(toImmutableList()); }
@Override public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) { Optional<Symbol> symbol = matcher.getAssignedSymbol(node, session, metadata, symbolAliases); if (symbol.isPresent() && alias.isPresent()) { return match(alias.get(), symbol.get().toSymbolReference()); } return new MatchResult(symbol.isPresent()); }
@Test public void testExpressionConstantFolding() { Expression originalExpression = comparison(GREATER_THAN, C_VARBINARY.toSymbolReference(), function("from_hex", stringLiteral("123456"))); ExtractionResult result = fromPredicate(originalExpression); assertEquals(result.getRemainingExpression(), TRUE_LITERAL); Slice value = Slices.wrappedBuffer(BaseEncoding.base16().decode("123456")); assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_VARBINARY, Domain.create(ValueSet.ofRanges(Range.greaterThan(VARBINARY, value)), false)))); Expression expression = toPredicate(result.getTupleDomain()); assertEquals(expression, comparison(GREATER_THAN, C_VARBINARY.toSymbolReference(), varbinaryLiteral(value))); }
@Test public void testFromUnprocessableInPredicate() { assertUnsupportedPredicate(new InPredicate(unprocessableExpression1(C_BIGINT), new InListExpression(ImmutableList.of(TRUE_LITERAL)))); assertUnsupportedPredicate(new InPredicate(C_BOOLEAN.toSymbolReference(), new InListExpression(ImmutableList.of(unprocessableExpression1(C_BOOLEAN))))); assertUnsupportedPredicate( new InPredicate(C_BOOLEAN.toSymbolReference(), new InListExpression(ImmutableList.of(TRUE_LITERAL, unprocessableExpression1(C_BOOLEAN))))); assertUnsupportedPredicate(not(new InPredicate(C_BOOLEAN.toSymbolReference(), new InListExpression(ImmutableList.of(unprocessableExpression1(C_BOOLEAN)))))); }
@Test void testNonImplictCastOnSymbolSide() { // we expect TupleDomain.all here(). // see comment in DomainTranslator.Visitor.visitComparisonExpression() assertUnsupportedPredicate(equal( new Cast(C_TIMESTAMP.toSymbolReference(), DATE.toString()), toExpression(DATE_VALUE, DATE))); assertUnsupportedPredicate(equal( new Cast(C_DECIMAL_12_2.toSymbolReference(), BIGINT.toString()), bigintLiteral(135L))); }