Scope scope = Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(fields.build())).build(); RelationPlan relationPlan = new RelationPlan(tableScan, scope, outputSymbols.build());
Scope outer = Scope.builder().withParent(root).withRelationType(RelationId.anonymous(), new RelationType(outerColumn1, outerColumn2)).build(); Scope inner = Scope.builder().withOuterQueryParent(outer).withRelationType(RelationId.anonymous(), new RelationType(innerColumn2, innerColumn3)).build();
public Builder withNamedQuery(String name, WithQuery withQuery) { checkArgument(!containsNamedQuery(name), "Query '%s' is already added", name); namedQueries.put(name, withQuery); return this; }
.map(column -> Field.newUnqualified(column.getName(), column.getType())) .collect(toImmutableList()); Scope scope = Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(fields)).build();
.withRelationType(RelationId.anonymous(), new RelationType(orderByAggregationSourceFields)) .build(); .withParent(orderByAggregationScope) .withRelationType(outputScope.getRelationId(), outputScope.getRelationType()) .build(); analysis.setScope(node, orderByScope); analysis.setOrderByAggregates(node, orderByAggregationExpressions);
.withParent(context.getContext().getScope()) .build(); Scope queryScope = analyzer.analyze(node.getQuery(), subqueryScope);
for (WithQuery withQuery : with.getQueries()) { Query query = withQuery.getQuery(); process(query, withScopeBuilder.build()); if (withScopeBuilder.containsNamedQuery(name)) { throw new SemanticException(DUPLICATE_RELATION, withQuery, "WITH query name '%s' specified more than once", name); withScopeBuilder.withNamedQuery(name, withQuery); Scope withScope = withScopeBuilder.build(); analysis.setScope(with, withScope); return withScope;
return new RelationPlan(projectNode, Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(newFields)).build(), newSymbols.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()); }
.withParent(context.getContext().getScope()) .withRelationType(RelationId.of(node), new RelationType(fields.build())) .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; }
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; } }
public static Builder builder() { return new Builder(); }
private Scope createAndAssignScope(Node node, Optional<Scope> parentScope, RelationType relationType) { Scope scope = scopeBuilder(parentScope) .withRelationType(RelationId.of(node), relationType) .build(); analysis.setScope(node, scope); return scope; }
private Scope createScope(Optional<Scope> parentScope) { return scopeBuilder(parentScope).build(); }
public static Scope create() { return builder().build(); }
@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; }