@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 Object getValue(Symbol symbol) { ColumnHandle column = assignments.get(symbol); checkArgument(column != null, "Missing column assignment for %s", symbol); if (!bindings.containsKey(column)) { return symbol.toSymbolReference(); } return bindings.get(column).getValue(); } }
@Override public Expression rewriteSymbolReference(SymbolReference node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { Symbol canonical = canonicalize(Symbol.from(node)); return canonical.toSymbolReference(); } }, value);
@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)); }
@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(); }
@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 static boolean isSemiJoinOutputReference(Expression conjunct, Symbol semiJoinOutput) { SymbolReference semiJoinOuputSymbolReference = semiJoinOutput.toSymbolReference(); return conjunct.equals(semiJoinOuputSymbolReference) || (conjunct instanceof NotExpression && ((NotExpression) conjunct).getValue().equals(semiJoinOuputSymbolReference)); }
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) { checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName()); ValuesNode valuesNode = (ValuesNode) node; if (!expectedRows.map(rows -> rows.equals(valuesNode.getRows())).orElse(true)) { return NO_MATCH; } return match(SymbolAliases.builder() .putAll(Maps.transformValues(outputSymbolAliases, index -> valuesNode.getOutputSymbols().get(index).toSymbolReference())) .build()); }
@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; } return match(outputAlias, semiJoinNode.getSemiJoinOutput().toSymbolReference()); }
@Test public void testValidTypeOnlyCoercion() { Expression expression = new Cast(columnB.toSymbolReference(), StandardTypes.BIGINT); Assignments assignments = Assignments.builder() .put(symbolAllocator.newSymbol(expression, BIGINT), expression) .put(symbolAllocator.newSymbol(columnE.toSymbolReference(), VARCHAR), columnE.toSymbolReference()) // implicit coercion from varchar(3) to varchar .build(); PlanNode node = new ProjectNode(newId(), baseTableScan, assignments); assertTypesValid(node); }
@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 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))); }
@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)))))); }