/** * Checks if give reference expression can resolved within given plan. */ private static Optional<Expression> tryResolveMissingExpression(PlanBuilder subPlan, Expression expression) { Expression rewritten = subPlan.rewrite(expression); if (rewritten != expression) { return Optional.of(rewritten); } return Optional.empty(); }
/** * Checks if give reference expression can resolved within given plan. */ private static Optional<Expression> tryResolveMissingExpression(PlanBuilder subPlan, Expression expression) { Expression rewritten = subPlan.rewrite(expression); if (rewritten != expression) { return Optional.of(rewritten); } return Optional.empty(); }
private PlanBuilder handleSubqueries(PlanBuilder subPlan, Node node, Iterable<Expression> inputs) { for (Expression input : inputs) { subPlan = subqueryPlanner.handleSubqueries(subPlan, subPlan.rewrite(input), node); } return subPlan; }
private PlanBuilder handleSubqueries(PlanBuilder subPlan, Node node, Iterable<Expression> inputs) { for (Expression input : inputs) { subPlan = subqueryPlanner.handleSubqueries(subPlan, subPlan.rewrite(input), node); } return subPlan; }
private PlanBuilder filter(PlanBuilder subPlan, Expression predicate, Node node) { if (predicate == null) { return subPlan; } // rewrite expressions which contain already handled subqueries Expression rewrittenBeforeSubqueries = subPlan.rewrite(predicate); subPlan = subqueryPlanner.handleSubqueries(subPlan, rewrittenBeforeSubqueries, node); Expression rewrittenAfterSubqueries = subPlan.rewrite(predicate); return subPlan.withNewRoot(new FilterNode(idAllocator.getNextId(), subPlan.getRoot(), rewrittenAfterSubqueries)); }
private PlanBuilder filter(PlanBuilder subPlan, Expression predicate, Node node) { if (predicate == null) { return subPlan; } // rewrite expressions which contain already handled subqueries Expression rewrittenBeforeSubqueries = subPlan.rewrite(predicate); subPlan = subqueryPlanner.handleSubqueries(subPlan, rewrittenBeforeSubqueries, node); Expression rewrittenAfterSubqueries = subPlan.rewrite(predicate); return subPlan.withNewRoot(new FilterNode(idAllocator.getNextId(), subPlan.getRoot(), rewrittenAfterSubqueries)); }
private Map<Symbol, Expression> coerce(Iterable<? extends Expression> expressions, PlanBuilder subPlan, TranslationMap translations) { ImmutableMap.Builder<Symbol, Expression> projections = ImmutableMap.builder(); for (Expression expression : expressions) { Type type = analysis.getType(expression); Type coercion = analysis.getCoercion(expression); Symbol symbol = symbolAllocator.newSymbol(expression, firstNonNull(coercion, type)); Expression rewritten = subPlan.rewrite(expression); if (coercion != null) { rewritten = new Cast( rewritten, coercion.getTypeSignature().toString(), false, metadata.getTypeManager().isTypeOnlyCoercion(type, coercion)); } projections.put(symbol, rewritten); translations.put(expression, symbol); } return projections.build(); }
private Map<Symbol, Expression> coerce(Iterable<? extends Expression> expressions, PlanBuilder subPlan, TranslationMap translations) { ImmutableMap.Builder<Symbol, Expression> projections = ImmutableMap.builder(); for (Expression expression : expressions) { Type type = analysis.getType(expression); Type coercion = analysis.getCoercion(expression); Symbol symbol = symbolAllocator.newSymbol(expression, firstNonNull(coercion, type)); Expression rewritten = subPlan.rewrite(expression); if (coercion != null) { rewritten = new Cast( rewritten, coercion.getTypeSignature().toString(), false, metadata.getTypeManager().isTypeOnlyCoercion(type, coercion)); } projections.put(symbol, rewritten); translations.put(expression, symbol); } return projections.build(); }
Expression leftExpression = leftPlanBuilder.rewrite(leftComparisonExpressions.get(i)); Expression rightExpression = rightPlanBuilder.rewrite(rightComparisonExpressions.get(i)); postInnerJoinConditions.add(new ComparisonExpression(joinConditionComparisonOperators.get(i), leftExpression, rightExpression)); postInnerJoinConditions.add(rootPlanBuilder.rewrite(expression));
Expression rewritten = subPlan.rewrite(windowFunction);
Expression rewritten = subPlan.rewrite(windowFunction);
Expression leftExpression = leftPlanBuilder.rewrite(leftComparisonExpressions.get(i)); Expression rightExpression = rightPlanBuilder.rewrite(rightComparisonExpressions.get(i)); postInnerJoinConditions.add(new ComparisonExpression(joinConditionComparisonOperators.get(i), leftExpression, rightExpression)); postInnerJoinConditions.add(rootPlanBuilder.rewrite(expression));
private PlanBuilder project(PlanBuilder subPlan, Iterable<Expression> expressions) { TranslationMap outputTranslations = new TranslationMap(subPlan.getRelationPlan(), analysis, lambdaDeclarationToSymbolMap); Assignments.Builder projections = Assignments.builder(); for (Expression expression : expressions) { if (expression instanceof SymbolReference) { Symbol symbol = Symbol.from(expression); projections.put(symbol, expression); outputTranslations.put(expression, symbol); continue; } Symbol symbol = symbolAllocator.newSymbol(expression, analysis.getTypeWithCoercions(expression)); projections.put(symbol, subPlan.rewrite(expression)); outputTranslations.put(expression, symbol); } return new PlanBuilder(outputTranslations, new ProjectNode( idAllocator.getNextId(), subPlan.getRoot(), projections.build()), analysis.getParameters()); }
private PlanBuilder project(PlanBuilder subPlan, Iterable<Expression> expressions) { TranslationMap outputTranslations = new TranslationMap(subPlan.getRelationPlan(), analysis, lambdaDeclarationToSymbolMap); Assignments.Builder projections = Assignments.builder(); for (Expression expression : expressions) { if (expression instanceof SymbolReference) { Symbol symbol = Symbol.from(expression); projections.put(symbol, expression); outputTranslations.put(expression, symbol); continue; } Symbol symbol = symbolAllocator.newSymbol(expression, analysis.getTypeWithCoercions(expression)); projections.put(symbol, subPlan.rewrite(expression)); outputTranslations.put(expression, symbol); } return new PlanBuilder(outputTranslations, new ProjectNode( idAllocator.getNextId(), subPlan.getRoot(), projections.build()), analysis.getParameters()); }
private PlanBuilder explicitCoercionFields(PlanBuilder subPlan, Iterable<Expression> alreadyCoerced, Iterable<? extends Expression> uncoerced) { TranslationMap translations = new TranslationMap(subPlan.getRelationPlan(), analysis, lambdaDeclarationToSymbolMap); Assignments.Builder projections = Assignments.builder(); projections.putAll(coerce(uncoerced, subPlan, translations)); for (Expression expression : alreadyCoerced) { if (expression instanceof SymbolReference) { // If this is an identity projection, no need to rewrite it // This is needed because certain synthetic identity expressions such as "group id" introduced when planning GROUPING // don't have a corresponding analysis, so the code below doesn't work for them projections.put(Symbol.from(expression), expression); continue; } Symbol symbol = symbolAllocator.newSymbol(expression, analysis.getType(expression)); Expression rewritten = subPlan.rewrite(expression); projections.put(symbol, rewritten); translations.put(expression, symbol); } return new PlanBuilder(translations, new ProjectNode( idAllocator.getNextId(), subPlan.getRoot(), projections.build()), analysis.getParameters()); }
private PlanBuilder explicitCoercionFields(PlanBuilder subPlan, Iterable<Expression> alreadyCoerced, Iterable<? extends Expression> uncoerced) { TranslationMap translations = new TranslationMap(subPlan.getRelationPlan(), analysis, lambdaDeclarationToSymbolMap); Assignments.Builder projections = Assignments.builder(); projections.putAll(coerce(uncoerced, subPlan, translations)); for (Expression expression : alreadyCoerced) { if (expression instanceof SymbolReference) { // If this is an identity projection, no need to rewrite it // This is needed because certain synthetic identity expressions such as "group id" introduced when planning GROUPING // don't have a corresponding analysis, so the code below doesn't work for them projections.put(Symbol.from(expression), expression); continue; } Symbol symbol = symbolAllocator.newSymbol(expression, analysis.getType(expression)); Expression rewritten = subPlan.rewrite(expression); projections.put(symbol, rewritten); translations.put(expression, symbol); } return new PlanBuilder(translations, new ProjectNode( idAllocator.getNextId(), subPlan.getRoot(), projections.build()), analysis.getParameters()); }