@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; }
public static Relation aliased(Relation relation, String alias, List<String> columnAliases) { return new AliasedRelation( relation, identifier(alias), columnAliases.stream() .map(QueryUtil::identifier) .collect(Collectors.toList())); }
private boolean isLateralRelation(Relation node) { if (node instanceof AliasedRelation) { return isLateralRelation(((AliasedRelation) node).getRelation()); } return node instanceof Unnest || node instanceof Lateral; }
@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 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; } }
@Override protected Void visitAliasedRelation(AliasedRelation node, Integer indentLevel) { print(indentLevel, "Alias[" + node.getAlias() + "]"); super.visitAliasedRelation(node, indentLevel + 1); return null; }
@Override protected R visitAliasedRelation(AliasedRelation node, C context) { return process(node.getRelation(), context); }
@Override protected Void visitAliasedRelation(AliasedRelation node, Integer indentLevel) { print(indentLevel, "Alias[" + node.getAlias() + "]"); super.visitAliasedRelation(node, indentLevel + 1); 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); }
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(); }
@Override protected Void visitAliasedRelation(AliasedRelation node, Integer indentLevel) { print(indentLevel, "Alias[" + node.getAlias() + "]"); super.visitAliasedRelation(node, indentLevel + 1); return null; }
@Override public Node visitAliasedRelation(SqlBaseParser.AliasedRelationContext context) { Relation child = (Relation) visit(context.relationPrimary()); if (context.identifier() == null) { return child; } List<Identifier> aliases = null; if (context.columnAliases() != null) { aliases = visit(context.columnAliases().identifier(), Identifier.class); } return new AliasedRelation(getLocation(context), child, (Identifier) visit(context.identifier()), aliases); }
@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; }
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(); }
Join.Type.IMPLICIT, new Table(QualifiedName.of("t")), new AliasedRelation(lateralRelation, identifier("a"), ImmutableList.of(identifier("x"))), Optional.empty())));
@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 R visitAliasedRelation(AliasedRelation node, C context) { return process(node.getRelation(), context); }
@Test public void testUnnest() { assertStatement("SELECT * FROM t CROSS JOIN UNNEST(a)", simpleQuery( selectList(new AllColumns()), new Join( Join.Type.CROSS, new Table(QualifiedName.of("t")), new Unnest(ImmutableList.of(new Identifier("a")), false), Optional.empty()))); assertStatement("SELECT * FROM t CROSS JOIN UNNEST(a, b) WITH ORDINALITY", simpleQuery( selectList(new AllColumns()), new Join( Join.Type.CROSS, new Table(QualifiedName.of("t")), new Unnest(ImmutableList.of(new Identifier("a"), new Identifier("b")), true), Optional.empty()))); assertStatement("SELECT * FROM t FULL JOIN UNNEST(a) AS tmp (c) ON true", simpleQuery( selectList(new AllColumns()), new Join( Join.Type.FULL, new Table(QualifiedName.of("t")), new AliasedRelation(new Unnest(ImmutableList.of(new Identifier("a")), false), new Identifier("tmp"), ImmutableList.of(new Identifier("c"))), Optional.of(new JoinOn(BooleanLiteral.TRUE_LITERAL))))); }
@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 R visitAliasedRelation(AliasedRelation node, C context) { return process(node.getRelation(), context); }