private boolean isLateralRelation(Relation node) { if (node instanceof AliasedRelation) { return isLateralRelation(((AliasedRelation) node).getRelation()); } return node instanceof Unnest || node instanceof Lateral; }
@Override protected R visitAliasedRelation(AliasedRelation node, C context) { return process(node.getRelation(), context); }
private Optional<Unnest> getUnnest(Relation relation) { if (relation instanceof AliasedRelation) { return getUnnest(((AliasedRelation) relation).getRelation()); } if (relation instanceof Unnest) { return Optional.of((Unnest) relation); } return Optional.empty(); }
private Optional<Lateral> getLateral(Relation relation) { if (relation instanceof AliasedRelation) { return getLateral(((AliasedRelation) relation).getRelation()); } if (relation instanceof Lateral) { return Optional.of((Lateral) relation); } return Optional.empty(); }
@Override protected Void visitAliasedRelation(AliasedRelation node, Integer indent) { process(node.getRelation(), indent); builder.append(' ') .append(formatExpression(node.getAlias(), parameters)); appendAliasColumns(builder, node.getColumnNames()); return null; }
@Override protected Scope visitAliasedRelation(AliasedRelation relation, Optional<Scope> scope) { Scope relationScope = process(relation.getRelation(), scope); // todo this check should be inside of TupleDescriptor.withAlias, but the exception needs the node object RelationType relationType = relationScope.getRelationType(); if (relation.getColumnNames() != null) { int totalColumns = relationType.getVisibleFieldCount(); if (totalColumns != relation.getColumnNames().size()) { throw new SemanticException(MISMATCHED_COLUMN_ALIASES, relation, "Column alias list has %s entries but '%s' has %s columns available", relation.getColumnNames().size(), relation.getAlias(), totalColumns); } } List<String> aliases = null; if (relation.getColumnNames() != null) { aliases = relation.getColumnNames().stream() .map(Identifier::getValue) .collect(Collectors.toList()); } RelationType descriptor = relationType.withAlias(relation.getAlias().getValue(), aliases); return createAndAssignScope(relation, scope, descriptor); }
@Override protected RelationPlan visitAliasedRelation(AliasedRelation node, Void context) { RelationPlan subPlan = process(node.getRelation(), context); PlanNode root = subPlan.getRoot(); List<Symbol> mappings = subPlan.getFieldMappings(); if (node.getColumnNames() != null) { ImmutableList.Builder<Symbol> newMappings = ImmutableList.<Symbol>builder(); Assignments.Builder assignments = Assignments.builder(); // project only the visible columns from the underlying relation for (int i = 0; i < subPlan.getDescriptor().getAllFieldCount(); i++) { Field field = subPlan.getDescriptor().getFieldByIndex(i); if (!field.isHidden()) { Symbol aliasedColumn = symbolAllocator.newSymbol(field); assignments.put(aliasedColumn, subPlan.getFieldMappings().get(i).toSymbolReference()); newMappings.add(aliasedColumn); } } root = new ProjectNode(idAllocator.getNextId(), subPlan.getRoot(), assignments.build()); mappings = newMappings.build(); } return new RelationPlan(root, analysis.getScope(node), mappings); }
@Override protected Void visitAliasedRelation(AliasedRelation node, Integer indent) { process(node.getRelation(), indent); builder.append(' ') .append(formatExpression(node.getAlias(), tableNameMapper, columnNameMapper, queryWithTables, escapeIdentifier)); appendAliasColumns(builder, node.getColumnNames()); return null; }
@Override protected R visitAliasedRelation(AliasedRelation node, C context) { return process(node.getRelation(), context); }
@Override protected R visitAliasedRelation(AliasedRelation node, C context) { return process(node.getRelation(), context); }
@Override protected Void visitAliasedRelation(AliasedRelation node, Integer indent) { process(node.getRelation(), indent); builder.append(' ') .append(node.getAlias()); appendAliasColumns(builder, node.getColumnNames()); return null; }
@Override protected Void visitAliasedRelation(AliasedRelation node, Integer indent) { process(node.getRelation(), indent); builder.append(' ') .append(node.getAlias()); appendAliasColumns(builder, node.getColumnNames()); return null; }
@Override protected Void visitAliasedRelation(AliasedRelation node, Integer indent) { process(node.getRelation(), indent); builder.append(' ') .append(formatExpression(node.getAlias(), parameters)); appendAliasColumns(builder, node.getColumnNames()); return null; }
@Override protected RelationPlan visitAliasedRelation(AliasedRelation node, Void context) { RelationPlan subPlan = process(node.getRelation(), context); RelationType outputDescriptor = analysis.getOutputDescriptor(node); return new RelationPlan(subPlan.getRoot(), outputDescriptor, subPlan.getOutputSymbols(), subPlan.getSampleWeight()); }
@Override protected RelationType visitAliasedRelation(AliasedRelation relation, AnalysisContext context) { RelationType child = process(relation.getRelation(), context); // todo this check should be inside of TupleDescriptor.withAlias, but the exception needs the node object if (relation.getColumnNames() != null) { int totalColumns = child.getVisibleFieldCount(); if (totalColumns != relation.getColumnNames().size()) { throw new SemanticException(MISMATCHED_COLUMN_ALIASES, relation, "Column alias list has %s entries but '%s' has %s columns available", relation.getColumnNames().size(), relation.getAlias(), totalColumns); } } RelationType descriptor = child.withAlias(relation.getAlias(), relation.getColumnNames()); analysis.setOutputDescriptor(relation, descriptor); return descriptor; }
@Override protected List<QuerySource> visitRelation(Relation node, QueryState state){ if(node instanceof Join){ return node.accept(this, state); }else if( node instanceof SampledRelation){ state.addException("Sampled relations are not supported"); return null; }else if( node instanceof AliasedRelation){ AliasedRelation ar = (AliasedRelation)node; state.setKeyValue("table_alias", ar.getAlias()); List<QuerySource> relations = ar.getRelation().accept(this, state); for(QuerySource rr : relations) rr.setAlias(ar.getAlias()); //.getValue()); return relations; }else if( node instanceof QueryBody){ return node.accept(this, state); }else{ state.addException("Unable to parse node because it has an unknown type :"+node.getClass()); return null; } }
if (node.getRight() instanceof Unnest || (node.getRight() instanceof AliasedRelation && ((AliasedRelation) node.getRight()).getRelation() instanceof Unnest)) { Unnest unnest; if (node.getRight() instanceof AliasedRelation) { unnest = (Unnest) ((AliasedRelation) node.getRight()).getRelation();