/** * Creates {@link RelationId} equal only to itself */ public static RelationId anonymous() { return new RelationId(null); }
private static int translateFieldToInteger(FieldId fieldId, RelationId requiredOriginRelationId) { // TODO: this section should be rewritten when support is added for GROUP BY columns to reference an outer scope checkState(fieldId.getRelationId().equals(requiredOriginRelationId), "grouping arguments must all come from the same relation"); return fieldId.getFieldIndex(); }
@Override public String toString() { if (isAnonymous()) { return toStringHelper(this) .addValue("anonymous") .addValue(format("x%08x", identityHashCode(this))) .toString(); } else { return toStringHelper(this) .addValue(sourceNode.getClass().getSimpleName()) .addValue(format("x%08x", identityHashCode(sourceNode))) .toString(); } } }
.withRelationType(RelationId.anonymous(), new RelationType(orderByAggregationSourceFields)) .build();
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; }
Scope scope = Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(fields.build())).build(); RelationPlan relationPlan = new RelationPlan(tableScan, scope, outputSymbols.build());
.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; }
/** * Creates {@link RelationId} equal to any {@link RelationId} created from exactly the same source. */ public static RelationId of(Node sourceNode) { return new RelationId(requireNonNull(sourceNode, "source cannot be null")); }
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()); }