Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2391,6 +2391,45 @@ public Node visitQuerySpecification(RelationalSqlParser.QuerySpecificationContex
Optional.empty());
}

@Override
public Node visitFromFirstQuerySpecification(
RelationalSqlParser.FromFirstQuerySpecificationContext ctx) {
Optional<Relation> from = Optional.empty();
List<SelectItem> selectItems = visit(ctx.selectItem(), SelectItem.class);

List<Relation> relations = visit(ctx.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(ctx), Join.Type.IMPLICIT, relation, iterator.next());
}

from = Optional.of(relation);
}
if (selectItems.isEmpty()) {
selectItems = ImmutableList.of(new AllColumns(getLocation(ctx), ImmutableList.of()));
}

NodeLocation selectLocation =
ctx.SELECT() != null ? getLocation(ctx.SELECT()) : getLocation(ctx);

return new QuerySpecification(
getLocation(ctx),
new Select(selectLocation, isDistinct(ctx.setQuantifier()), selectItems),
from,
visitIfPresent(ctx.where, Expression.class),
visitIfPresent(ctx.groupBy(), GroupBy.class),
visitIfPresent(ctx.having, Expression.class),
Optional.empty(),
visit(ctx.windowDefinition(), WindowDefinition.class),
Optional.empty(),
Optional.empty(),
Optional.empty());
}

@Override
public Node visitSelectSingle(RelationalSqlParser.SelectSingleContext ctx) {
if (ctx.identifier() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ queryPrimary
| TABLE qualifiedName #table
| VALUES expression (',' expression)* #inlineTable
| '(' queryNoWith ')' #subquery
| fromFirstQuerySpecification #fromFirstQueryPrimary
;

sortItem
Expand All @@ -1011,6 +1012,15 @@ querySpecification
(WINDOW windowDefinition (',' windowDefinition)*)?
;

fromFirstQuerySpecification
: FROM relation (',' relation)*
(SELECT setQuantifier? selectItem (',' selectItem)*)?
(WHERE where=booleanExpression)?
(GROUP BY groupBy)?
(HAVING having=booleanExpression)?
(WINDOW windowDefinition (',' windowDefinition)*)?
;

groupBy
: setQuantifier? groupingElement (',' groupingElement)*
;
Expand Down Expand Up @@ -2010,4 +2020,4 @@ WS
// when splitting statements with DelimiterLexer
UNRECOGNIZED
: .
;
;