Search in sources :

Example 1 with Identifier

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

the class AstBuilder method visitAliasedRelation.

@Override
public Node visitAliasedRelation(SqlBaseParser.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);
}
Also used : SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) Identifier(io.prestosql.sql.tree.Identifier) AliasedRelation(io.prestosql.sql.tree.AliasedRelation)

Example 2 with Identifier

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

the class AstBuilder method visitJoinRelation.

// *************** from clause *****************
@Override
public Node visitJoinRelation(SqlBaseParser.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());
    }
    JoinCriteria criteria;
    if (context.NATURAL() != null) {
        right = (Relation) visit(context.right);
        criteria = new NaturalJoin();
    } else {
        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));
}
Also used : SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) Identifier(io.prestosql.sql.tree.Identifier) 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) JoinCriteria(io.prestosql.sql.tree.JoinCriteria) Join(io.prestosql.sql.tree.Join) NaturalJoin(io.prestosql.sql.tree.NaturalJoin) JoinUsing(io.prestosql.sql.tree.JoinUsing) NaturalJoin(io.prestosql.sql.tree.NaturalJoin) JoinOn(io.prestosql.sql.tree.JoinOn)

Example 3 with Identifier

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

the class TestSqlParser method testCreateTableAsWith.

@Test
public void testCreateTableAsWith() {
    String queryParenthesizedWith = "CREATE TABLE foo " + "AS " + "( WITH t(x) AS (VALUES 1) " + "TABLE t ) " + "WITH NO DATA";
    String queryUnparenthesizedWith = "CREATE TABLE foo " + "AS " + "WITH t(x) AS (VALUES 1) " + "TABLE t " + "WITH NO DATA";
    String queryParenthesizedWithHasAlias = "CREATE TABLE foo(a) " + "AS " + "( WITH t(x) AS (VALUES 1) " + "TABLE t ) " + "WITH NO DATA";
    String queryUnparenthesizedWithHasAlias = "CREATE TABLE foo(a) " + "AS " + "WITH t(x) AS (VALUES 1) " + "TABLE t " + "WITH NO DATA";
    QualifiedName table = QualifiedName.of("foo");
    Query query = new Query(Optional.of(new With(false, ImmutableList.of(new WithQuery(identifier("t"), query(new Values(ImmutableList.of(new LongLiteral("1")))), Optional.of(ImmutableList.of(identifier("x"))))))), new Table(QualifiedName.of("t")), Optional.empty(), Optional.empty(), Optional.empty());
    assertStatement(queryParenthesizedWith, new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.empty(), Optional.empty()));
    assertStatement(queryUnparenthesizedWith, new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.empty(), Optional.empty()));
    assertStatement(queryParenthesizedWithHasAlias, new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.of(ImmutableList.of(new Identifier("a"))), Optional.empty()));
    assertStatement(queryUnparenthesizedWithHasAlias, new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.of(ImmutableList.of(new Identifier("a"))), Optional.empty()));
}
Also used : Table(io.prestosql.sql.tree.Table) CreateTable(io.prestosql.sql.tree.CreateTable) VacuumTable(io.prestosql.sql.tree.VacuumTable) DropTable(io.prestosql.sql.tree.DropTable) RenameTable(io.prestosql.sql.tree.RenameTable) Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) QueryUtil.simpleQuery(io.prestosql.sql.QueryUtil.simpleQuery) Query(io.prestosql.sql.tree.Query) WithQuery(io.prestosql.sql.tree.WithQuery) LongLiteral(io.prestosql.sql.tree.LongLiteral) WithQuery(io.prestosql.sql.tree.WithQuery) QualifiedName(io.prestosql.sql.tree.QualifiedName) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) Values(io.prestosql.sql.tree.Values) With(io.prestosql.sql.tree.With) Test(org.testng.annotations.Test)

Example 4 with Identifier

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

the class TestSqlParser method testInsertIntoCube.

@Test
public void testInsertIntoCube() {
    assertStatement("INSERT INTO CUBE foo WHERE d1 > 10", new InsertCube(QualifiedName.of("foo"), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("d1"), new LongLiteral("10"))), false));
    assertStatement("INSERT INTO CUBE c1.s1.foo WHERE d1 > 10", new InsertCube(QualifiedName.of("c1", "s1", "foo"), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("d1"), new LongLiteral("10"))), false));
}
Also used : ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) LongLiteral(io.prestosql.sql.tree.LongLiteral) InsertCube(io.prestosql.sql.tree.InsertCube) Test(org.testng.annotations.Test)

Example 5 with Identifier

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

the class TestSqlParser method testCreateTable.

@Test
public void testCreateTable() {
    assertStatement("CREATE TABLE foo (a VARCHAR, b BIGINT COMMENT 'hello world', c IPADDRESS)", new CreateTable(QualifiedName.of("foo"), ImmutableList.of(new ColumnDefinition(identifier("a"), "VARCHAR", true, emptyList(), Optional.empty()), new ColumnDefinition(identifier("b"), "BIGINT", true, emptyList(), Optional.of("hello world")), new ColumnDefinition(identifier("c"), "IPADDRESS", true, emptyList(), Optional.empty())), false, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    // with properties
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP WITH (nullable = true, compression = 'LZ4'))", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, ImmutableList.of(new Property(new Identifier("nullable"), BooleanLiteral.TRUE_LITERAL), new Property(new Identifier("compression"), new StringLiteral("LZ4"))), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    // with LIKE
    assertStatement("CREATE TABLE IF NOT EXISTS bar (LIKE like_table)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new LikeClause(QualifiedName.of("like_table"), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP, LIKE like_table)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP, LIKE like_table, d DATE)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.empty()), new ColumnDefinition(identifier("d"), "DATE", true, emptyList(), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (LIKE like_table INCLUDING PROPERTIES)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new LikeClause(QualifiedName.of("like_table"), Optional.of(LikeClause.PropertiesOption.INCLUDING))), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP, LIKE like_table EXCLUDING PROPERTIES)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.of(LikeClause.PropertiesOption.EXCLUDING))), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP, LIKE like_table EXCLUDING PROPERTIES) COMMENT 'test'", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.of(LikeClause.PropertiesOption.EXCLUDING))), true, ImmutableList.of(), Optional.of("test")));
}
Also used : LikeClause(io.prestosql.sql.tree.LikeClause) Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) StringLiteral(io.prestosql.sql.tree.StringLiteral) CreateTable(io.prestosql.sql.tree.CreateTable) Property(io.prestosql.sql.tree.Property) ColumnDefinition(io.prestosql.sql.tree.ColumnDefinition) Test(org.testng.annotations.Test)

Aggregations

Identifier (io.prestosql.sql.tree.Identifier)65 Test (org.testng.annotations.Test)34 QueryUtil.quotedIdentifier (io.prestosql.sql.QueryUtil.quotedIdentifier)29 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)20 Expression (io.prestosql.sql.tree.Expression)19 StringLiteral (io.prestosql.sql.tree.StringLiteral)17 LongLiteral (io.prestosql.sql.tree.LongLiteral)16 Property (io.prestosql.sql.tree.Property)16 ArrayList (java.util.ArrayList)16 FunctionCall (io.prestosql.sql.tree.FunctionCall)15 CreateTable (io.prestosql.sql.tree.CreateTable)14 QuantifiedComparisonExpression (io.prestosql.sql.tree.QuantifiedComparisonExpression)13 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)12 QualifiedName (io.prestosql.sql.tree.QualifiedName)12 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)11 Table (io.prestosql.sql.tree.Table)11 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)10 CoalesceExpression (io.prestosql.sql.tree.CoalesceExpression)9 DropTable (io.prestosql.sql.tree.DropTable)9 IfExpression (io.prestosql.sql.tree.IfExpression)9