use of io.prestosql.sql.tree.QueryBody in project hetu-core by openlookeng.
the class ImpalaAstBuilder method visitQueryNoWith.
@Override
public Node visitQueryNoWith(ImpalaSqlParser.QueryNoWithContext context) {
QueryBody term = (QueryBody) visit(context.queryTerm());
Optional<OrderBy> orderBy = Optional.empty();
if (context.ORDER() != null) {
orderBy = Optional.of(new OrderBy(getLocation(context.ORDER()), visit(context.sortItem(), SortItem.class)));
}
Optional<Node> limit = Optional.empty();
Optional<Offset> offset = Optional.empty();
if (context.LIMIT() != null) {
Optional<String> offsetValue = getTextIfPresent(context.offset);
Optional<String> rowsValue = getTextIfPresent(context.rows);
if (offsetValue.isPresent()) {
offset = Optional.of(new Offset(offsetValue.get()));
}
if (rowsValue.isPresent()) {
limit = Optional.of(new Limit(rowsValue.get()));
}
}
if (term instanceof QuerySpecification) {
// When we have a simple query specification
// followed by order by, offset, limit or fetch,
// fold the order by, limit, offset or fetch clauses
// into the query specification (analyzer/planner
// expects this structure to resolve references with respect
// to columns defined in the query specification)
QuerySpecification query = (QuerySpecification) term;
return new Query(getLocation(context), Optional.empty(), new QuerySpecification(getLocation(context), query.getSelect(), query.getFrom(), query.getWhere(), query.getGroupBy(), query.getHaving(), orderBy, offset, limit), Optional.empty(), Optional.empty(), Optional.empty());
}
return new Query(getLocation(context), Optional.empty(), term, orderBy, offset, limit);
}
use of io.prestosql.sql.tree.QueryBody in project hetu-core by openlookeng.
the class HiveAstBuilder method visitQueryNoWith.
@Override
public Node visitQueryNoWith(HiveSqlParser.QueryNoWithContext context) {
QueryBody term = (QueryBody) visit(context.queryTerm());
Optional<OrderBy> orderBy = Optional.empty();
if (context.ORDER() != null) {
orderBy = Optional.of(new OrderBy(getLocation(context.ORDER()), visit(context.sortItem(), SortItem.class)));
}
if (context.clusteredBy() != null) {
addDiff(DiffType.UNSUPPORTED, context.CLUSTER().getText(), "[CLUSTERED BY] is not supported");
throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported attribute: CLUSTERED BY", context.clusteredBy());
}
if (context.distributeBy() != null) {
addDiff(DiffType.UNSUPPORTED, context.DISTRIBUTE().getText(), "[DISTRIBUTE BY] is not supported");
throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported attribute: DISTRIBUTE BY", context.distributeBy());
}
if (context.sortedBy() != null) {
addDiff(DiffType.UNSUPPORTED, context.SORT().getText(), "[SORT BY] is not supported");
throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported attribute: SORT BY", context.sortedBy());
}
Optional<Node> limit = Optional.empty();
Optional<Offset> offset = Optional.empty();
if (context.LIMIT() != null) {
Optional<String> offsetValue = getTextIfPresent(context.offset);
Optional<String> rowsValue = getTextIfPresent(context.rows);
if (offsetValue.isPresent()) {
offset = Optional.of(new Offset(offsetValue.get()));
}
if (rowsValue.isPresent()) {
limit = Optional.of(new Limit(rowsValue.get()));
}
}
if (term instanceof QuerySpecification) {
QuerySpecification query = (QuerySpecification) term;
return new Query(getLocation(context), Optional.empty(), new QuerySpecification(getLocation(context), query.getSelect(), query.getFrom(), query.getWhere(), query.getGroupBy(), query.getHaving(), orderBy, offset, limit), Optional.empty(), Optional.empty(), Optional.empty());
}
return new Query(getLocation(context), Optional.empty(), term, orderBy, offset, limit);
}
Aggregations