public static Scope create() { return builder().build(); }
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; } }
@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); }
.collect(toImmutableList()); Scope orderByAggregationScope = Scope.builder() .withRelationType(RelationId.anonymous(), new RelationType(orderByAggregationSourceFields)) .build(); Scope orderByScope = Scope.builder() .withParent(orderByAggregationScope) .withRelationType(outputScope.getRelationId(), outputScope.getRelationType())
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; }
Scope lambdaScope = Scope.builder() .withParent(context.getContext().getScope()) .withRelationType(RelationId.of(node), new RelationType(fields.build()))
Scope scope = Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(fields.build())).build(); RelationPlan relationPlan = new RelationPlan(tableScan, scope, outputSymbols.build());
@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; }
Scope subqueryScope = Scope.builder() .withParent(context.getContext().getScope()) .build();
return new RelationPlan(projectNode, Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(newFields)).build(), newSymbols.build());
.map(column -> Field.newUnqualified(column.getName(), column.getType())) .collect(toImmutableList()); Scope scope = Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(fields)).build();
private static ExpressionAnalysis analyzeExpressions( Session session, Metadata metadata, SqlParser sqlParser, RelationType tupleDescriptor, TypeProvider types, Iterable<? extends Expression> expressions, List<Expression> parameters, WarningCollector warningCollector, boolean isDescribe) { // expressions at this point can not have sub queries so deny all access checks // in the future, we will need a full access controller here to verify access to functions Analysis analysis = new Analysis(null, parameters, isDescribe); ExpressionAnalyzer analyzer = create(analysis, session, metadata, sqlParser, new DenyAllAccessControl(), types, warningCollector); for (Expression expression : expressions) { analyzer.analyze(expression, Scope.builder().withRelationType(RelationId.anonymous(), tupleDescriptor).build()); } return new ExpressionAnalysis( analyzer.getExpressionTypes(), analyzer.getExpressionCoercions(), analyzer.getSubqueryInPredicates(), analyzer.getScalarSubqueries(), analyzer.getExistsSubqueries(), analyzer.getColumnReferences(), analyzer.getTypeOnlyCoercions(), analyzer.getQuantifiedComparisons(), analyzer.getLambdaArgumentReferences(), analyzer.getWindowFunctions()); }