Search in sources :

Example 1 with SelectItem

use of io.prestosql.sql.tree.SelectItem in project hetu-core by openlookeng.

the class AstBuilder method visitQuerySpecification.

@Override
public Node visitQuerySpecification(SqlBaseParser.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());
}
Also used : QuerySpecification(io.prestosql.sql.tree.QuerySpecification) SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) GroupBy(io.prestosql.sql.tree.GroupBy) SimpleGroupBy(io.prestosql.sql.tree.SimpleGroupBy) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) LambdaExpression(io.prestosql.sql.tree.LambdaExpression) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) BindExpression(io.prestosql.sql.tree.BindExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) IfExpression(io.prestosql.sql.tree.IfExpression) InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) TryExpression(io.prestosql.sql.tree.TryExpression) SelectItem(io.prestosql.sql.tree.SelectItem) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) Select(io.prestosql.sql.tree.Select) Join(io.prestosql.sql.tree.Join) NaturalJoin(io.prestosql.sql.tree.NaturalJoin)

Example 2 with SelectItem

use of io.prestosql.sql.tree.SelectItem 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());
}
Also used : QuerySpecification(io.prestosql.sql.tree.QuerySpecification) SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) GroupBy(io.prestosql.sql.tree.GroupBy) SimpleGroupBy(io.prestosql.sql.tree.SimpleGroupBy) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) LambdaExpression(io.prestosql.sql.tree.LambdaExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) IfExpression(io.prestosql.sql.tree.IfExpression) InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) SelectItem(io.prestosql.sql.tree.SelectItem) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) Select(io.prestosql.sql.tree.Select) Join(io.prestosql.sql.tree.Join)

Example 3 with SelectItem

use of io.prestosql.sql.tree.SelectItem 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());
}
Also used : QuerySpecification(io.prestosql.sql.tree.QuerySpecification) SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) GroupBy(io.prestosql.sql.tree.GroupBy) SimpleGroupBy(io.prestosql.sql.tree.SimpleGroupBy) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) IfExpression(io.prestosql.sql.tree.IfExpression) InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) SelectItem(io.prestosql.sql.tree.SelectItem) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) Select(io.prestosql.sql.tree.Select) Join(io.prestosql.sql.tree.Join)

Example 4 with SelectItem

use of io.prestosql.sql.tree.SelectItem in project hetu-core by openlookeng.

the class QueryRewriter method checksumSql.

private String checksumSql(List<Column> columns, QualifiedName table) throws QueryRewriteException {
    if (columns.isEmpty()) {
        throw new QueryRewriteException("Table " + table + " has no columns");
    }
    ImmutableList.Builder<SelectItem> selectItems = ImmutableList.builder();
    for (Column column : columns) {
        Expression expression = new Identifier(column.getName());
        if (column.isApproximateType()) {
            expression = new FunctionCall(QualifiedName.of("round"), ImmutableList.of(expression, new LongLiteral(Integer.toString(doublePrecision))));
        }
        selectItems.add(new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(expression))));
    }
    Select select = new Select(false, selectItems.build());
    return formatSql(new QuerySpecification(select, Optional.of(new Table(table)), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty());
}
Also used : Table(io.prestosql.sql.tree.Table) DropTable(io.prestosql.sql.tree.DropTable) CreateTable(io.prestosql.sql.tree.CreateTable) LongLiteral(io.prestosql.sql.tree.LongLiteral) ImmutableList(com.google.common.collect.ImmutableList) SingleColumn(io.prestosql.sql.tree.SingleColumn) QuerySpecification(io.prestosql.sql.tree.QuerySpecification) Identifier(io.prestosql.sql.tree.Identifier) SingleColumn(io.prestosql.sql.tree.SingleColumn) Expression(io.prestosql.sql.tree.Expression) SelectItem(io.prestosql.sql.tree.SelectItem) Select(io.prestosql.sql.tree.Select) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) FunctionCall(io.prestosql.sql.tree.FunctionCall)

Aggregations

CreateTableAsSelect (io.prestosql.sql.tree.CreateTableAsSelect)4 Expression (io.prestosql.sql.tree.Expression)4 QuerySpecification (io.prestosql.sql.tree.QuerySpecification)4 Select (io.prestosql.sql.tree.Select)4 SelectItem (io.prestosql.sql.tree.SelectItem)4 AliasedRelation (io.prestosql.sql.tree.AliasedRelation)3 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)3 ArithmeticUnaryExpression (io.prestosql.sql.tree.ArithmeticUnaryExpression)3 CoalesceExpression (io.prestosql.sql.tree.CoalesceExpression)3 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)3 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)3 GroupBy (io.prestosql.sql.tree.GroupBy)3 IfExpression (io.prestosql.sql.tree.IfExpression)3 InListExpression (io.prestosql.sql.tree.InListExpression)3 Join (io.prestosql.sql.tree.Join)3 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)3 NotExpression (io.prestosql.sql.tree.NotExpression)3 NullIfExpression (io.prestosql.sql.tree.NullIfExpression)3 QuantifiedComparisonExpression (io.prestosql.sql.tree.QuantifiedComparisonExpression)3 Relation (io.prestosql.sql.tree.Relation)3