use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.
the class ImpalaAstBuilder method visitQuerySpecification.
@Override
public Node visitQuerySpecification(ImpalaSqlParser.QuerySpecificationContext context) {
Optional<Relation> from = Optional.empty();
List<SelectItem> selectItems = visit(context.selectItem(), SelectItem.class);
List<Relation> relations = visit(context.relation(), Relation.class);
if (!relations.isEmpty()) {
// synthesize implicit join nodes
Iterator<Relation> iterator = relations.iterator();
Relation relation = iterator.next();
while (iterator.hasNext()) {
relation = new Join(getLocation(context), Join.Type.IMPLICIT, relation, iterator.next(), Optional.empty());
}
from = Optional.of(relation);
}
return new QuerySpecification(getLocation(context), new Select(getLocation(context.SELECT()), isDistinct(context.setQuantifier()), selectItems), from, visitIfPresent(context.where, Expression.class), visitIfPresent(context.groupBy(), GroupBy.class), visitIfPresent(context.having, Expression.class), Optional.empty(), Optional.empty(), Optional.empty());
}
use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.
the class RelationPlanner method process.
private SetOperationPlan process(SetOperation node) {
List<Symbol> outputs = null;
ImmutableList.Builder<PlanNode> sources = ImmutableList.builder();
ImmutableListMultimap.Builder<Symbol, Symbol> symbolMapping = ImmutableListMultimap.builder();
List<RelationPlan> subPlans = node.getRelations().stream().map(relation -> processAndCoerceIfNecessary(relation, null)).collect(toImmutableList());
for (RelationPlan relationPlan : subPlans) {
List<Symbol> childOutputSymbols = relationPlan.getFieldMappings();
if (outputs == null) {
// Use the first Relation to derive output symbol names
RelationType descriptor = relationPlan.getDescriptor();
ImmutableList.Builder<Symbol> outputSymbolBuilder = ImmutableList.builder();
for (Field field : descriptor.getVisibleFields()) {
int fieldIndex = descriptor.indexOf(field);
Symbol symbol = childOutputSymbols.get(fieldIndex);
outputSymbolBuilder.add(planSymbolAllocator.newSymbol(symbol.getName(), planSymbolAllocator.getTypes().get(symbol)));
}
outputs = outputSymbolBuilder.build();
}
RelationType descriptor = relationPlan.getDescriptor();
checkArgument(descriptor.getVisibleFieldCount() == outputs.size(), "Expected relation to have %s symbols but has %s symbols", descriptor.getVisibleFieldCount(), outputs.size());
int fieldId = 0;
for (Field field : descriptor.getVisibleFields()) {
int fieldIndex = descriptor.indexOf(field);
symbolMapping.put(outputs.get(fieldId), childOutputSymbols.get(fieldIndex));
fieldId++;
}
sources.add(relationPlan.getRoot());
}
return new SetOperationPlan(sources.build(), symbolMapping.build());
}
use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.
the class ImpalaAstBuilder method visitAliasedRelation.
@Override
public Node visitAliasedRelation(ImpalaSqlParser.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);
}
use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.
the class ImpalaAstBuilder method visitJoinRelation.
@Override
public Node visitJoinRelation(ImpalaSqlParser.JoinRelationContext context) {
Relation left = (Relation) visit(context.left);
Relation right;
if (context.CROSS() != null) {
right = (Relation) visit(context.right);
return new Join(getLocation(context), Join.Type.CROSS, left, right, Optional.empty());
}
if (context.joinType().SEMI() != null) {
addDiff(DiffType.UNSUPPORTED, context.joinType().SEMI().getText(), "[SEMI] is not supported");
throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "SEMI", context);
}
if (context.joinType().ANTI() != null) {
addDiff(DiffType.UNSUPPORTED, context.joinType().ANTI().getText(), "[ANTI] is not supported");
throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "ANTI", context);
}
if (context.joinType().INNER() != null && (context.joinType().LEFT() != null || context.joinType().RIGHT() != null)) {
addDiff(DiffType.UNSUPPORTED, context.joinType().INNER().getText(), "[LEFT INNER || RIGHT INNER] is not supported");
throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "LEFT INNER || RIGHT INNER", context);
}
JoinCriteria criteria;
right = (Relation) visit(context.rightRelation);
if (context.joinCriteria().ON() != null) {
criteria = new JoinOn((Expression) visit(context.joinCriteria().booleanExpression()));
} else if (context.joinCriteria().USING() != null) {
criteria = new JoinUsing(visit(context.joinCriteria().identifier(), Identifier.class));
} else {
throw new IllegalArgumentException("Unsupported join criteria");
}
Join.Type joinType;
if (context.joinType().LEFT() != null) {
joinType = Join.Type.LEFT;
} else if (context.joinType().RIGHT() != null) {
joinType = Join.Type.RIGHT;
} else if (context.joinType().FULL() != null) {
joinType = Join.Type.FULL;
} else {
joinType = Join.Type.INNER;
}
return new Join(getLocation(context), joinType, left, right, Optional.of(criteria));
}
use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.
the class HiveAstBuilder method visitQuerySpecification.
@Override
public Node visitQuerySpecification(HiveSqlParser.QuerySpecificationContext context) {
if (context.lateralView().size() > 0) {
addDiff(DiffType.UNSUPPORTED, context.LATERAL(0).getText(), "[LATERAL VIEW] is not supported");
addDiff(DiffType.UNSUPPORTED, context.VIEW(0).getText(), null);
throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: LATERAL VIEW", context.lateralView(0));
}
Optional<Relation> from = Optional.empty();
List<SelectItem> selectItems = visit(context.selectItem(), SelectItem.class);
List<Relation> relations = visit(context.relation(), Relation.class);
if (!relations.isEmpty()) {
// synthesize implicit join nodes
Iterator<Relation> iterator = relations.iterator();
Relation relation = iterator.next();
while (iterator.hasNext()) {
relation = new Join(getLocation(context), Join.Type.IMPLICIT, relation, iterator.next(), Optional.empty());
}
from = Optional.of(relation);
}
return new QuerySpecification(getLocation(context), new Select(getLocation(context.SELECT()), isDistinct(context.setQuantifier()), selectItems), from, visitIfPresent(context.where, Expression.class), visitIfPresent(context.groupBy(), GroupBy.class), visitIfPresent(context.having, Expression.class), Optional.empty(), Optional.empty(), Optional.empty());
}
Aggregations