@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()); 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 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 Void visitAliasedRelation(AliasedRelation node, Integer indent) { process(node.getRelation(), indent); builder.append(' ') .append(formatName(node.getAlias())); 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 Void visitAliasedRelation(AliasedRelation node, Integer indent) { process(node.getRelation(), indent); builder.append(' ') .append(node.getAlias()); appendAliasColumns(builder, node.getColumnNames()); return null; }
@Override public Node visitAliasedRelation(SqlBaseParser.AliasedRelationContext context) { Relation child = (Relation) visit(context.relationPrimary()); if (context.identifier() == null) { return child; } return new AliasedRelation(getLocation(context), child, context.identifier().getText(), getColumnAliases(context.columnAliases())); }
public static Relation aliased(Relation relation, String alias, List<String> columnAliases) { return new AliasedRelation(relation, alias, columnAliases); }