private Scope.Builder scopeBuilder(Optional<Scope> parentScope) { Scope.Builder scopeBuilder = Scope.builder(); if (parentScope.isPresent()) { // parent scope represents local query scope hierarchy. Local query scope // hierarchy should have outer query scope as ancestor already. scopeBuilder.withParent(parentScope.get()); } else if (outerQueryScope.isPresent()) { scopeBuilder.withOuterQueryParent(outerQueryScope.get()); } return scopeBuilder; } }
private Scope.Builder scopeBuilder(Optional<Scope> parentScope) { Scope.Builder scopeBuilder = Scope.builder(); if (parentScope.isPresent()) { // parent scope represents local query scope hierarchy. Local query scope // hierarchy should have outer query scope as ancestor already. scopeBuilder.withParent(parentScope.get()); } else if (outerQueryScope.isPresent()) { scopeBuilder.withOuterQueryParent(outerQueryScope.get()); } return scopeBuilder; } }
.withParent(orderByAggregationScope) .withRelationType(outputScope.getRelationId(), outputScope.getRelationType()) .build();
.withParent(orderByAggregationScope) .withRelationType(outputScope.getRelationId(), outputScope.getRelationType()) .build();
Scope outer = Scope.builder().withParent(root).withRelationType(RelationId.anonymous(), new RelationType(outerColumn1, outerColumn2)).build();
Scope outer = Scope.builder().withParent(root).withRelationType(RelationId.anonymous(), new RelationType(outerColumn1, outerColumn2)).build();
.withParent(context.getContext().getScope()) .withRelationType(RelationId.of(node), new RelationType(fields.build())) .build();
.withParent(context.getContext().getScope()) .build(); Scope queryScope = analyzer.analyze(node.getQuery(), subqueryScope);
.withParent(context.getContext().getScope()) .withRelationType(RelationId.of(node), new RelationType(fields.build())) .build();
.withParent(context.getContext().getScope()) .build(); Scope queryScope = analyzer.analyze(node.getQuery(), subqueryScope);
@Override protected Scope visitQuery(Query node, Optional<Scope> scope) { Scope withScope = analyzeWith(node, scope); Scope queryBodyScope = process(node.getQueryBody(), withScope); if (node.getOrderBy().isPresent()) { analyzeOrderBy(node, queryBodyScope); } else { analysis.setOrderByExpressions(node, emptyList()); } // Input fields == Output fields analysis.setOutputExpressions(node, descriptorToFields(queryBodyScope)); Scope queryScope = Scope.builder() .withParent(withScope) .withRelationType(RelationId.of(node), queryBodyScope.getRelationType()) .build(); analysis.setScope(node, queryScope); return queryScope; }
@Override protected Scope visitQuery(Query node, Optional<Scope> scope) { Scope withScope = analyzeWith(node, scope); Scope queryBodyScope = process(node.getQueryBody(), withScope); if (node.getOrderBy().isPresent()) { analyzeOrderBy(node, queryBodyScope); } else { analysis.setOrderByExpressions(node, emptyList()); } // Input fields == Output fields analysis.setOutputExpressions(node, descriptorToFields(queryBodyScope)); Scope queryScope = Scope.builder() .withParent(withScope) .withRelationType(RelationId.of(node), queryBodyScope.getRelationType()) .build(); analysis.setScope(node, queryScope); return queryScope; }
@Override protected Type visitExists(ExistsPredicate node, StackableAstVisitorContext<Context> context) { StatementAnalyzer analyzer = statementAnalyzerFactory.apply(node); Scope subqueryScope = Scope.builder().withParent(context.getContext().getScope()).build(); analyzer.analyze(node.getSubquery(), subqueryScope); existsSubqueries.add(NodeRef.of(node)); return setExpressionType(node, BOOLEAN); }
private Scope computeAndAssignOrderByScope(OrderBy node, Scope sourceScope, Scope outputScope) { // ORDER BY should "see" both output and FROM fields during initial analysis and non-aggregation query planning Scope orderByScope = Scope.builder() .withParent(sourceScope) .withRelationType(outputScope.getRelationId(), outputScope.getRelationType()) .build(); analysis.setScope(node, orderByScope); return orderByScope; }
@Override protected Type visitExists(ExistsPredicate node, StackableAstVisitorContext<Context> context) { StatementAnalyzer analyzer = statementAnalyzerFactory.apply(node); Scope subqueryScope = Scope.builder().withParent(context.getContext().getScope()).build(); analyzer.analyze(node.getSubquery(), subqueryScope); existsSubqueries.add(NodeRef.of(node)); return setExpressionType(node, BOOLEAN); }
private Scope computeAndAssignOrderByScope(OrderBy node, Scope sourceScope, Scope outputScope) { // ORDER BY should "see" both output and FROM fields during initial analysis and non-aggregation query planning Scope orderByScope = Scope.builder() .withParent(sourceScope) .withRelationType(outputScope.getRelationId(), outputScope.getRelationType()) .build(); analysis.setScope(node, orderByScope); return orderByScope; }