Search in sources :

Example 1 with LongLiteral

use of io.prestosql.sql.tree.LongLiteral 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 2 with LongLiteral

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

the class TestSqlParser method testArrayConstructor.

@Test
public void testArrayConstructor() {
    assertExpression("ARRAY []", new ArrayConstructor(ImmutableList.of()));
    assertExpression("ARRAY [1, 2]", new ArrayConstructor(ImmutableList.of(new LongLiteral("1"), new LongLiteral("2"))));
    assertExpression("ARRAY [1e0, 2.5e0]", new ArrayConstructor(ImmutableList.of(new DoubleLiteral("1.0"), new DoubleLiteral("2.5"))));
    assertExpression("ARRAY ['hi']", new ArrayConstructor(ImmutableList.of(new StringLiteral("hi"))));
    assertExpression("ARRAY ['hi', 'hello']", new ArrayConstructor(ImmutableList.of(new StringLiteral("hi"), new StringLiteral("hello"))));
}
Also used : StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) ArrayConstructor(io.prestosql.sql.tree.ArrayConstructor) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) Test(org.testng.annotations.Test)

Example 3 with LongLiteral

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

the class TestSqlParser method testArraySubscript.

@Test
public void testArraySubscript() {
    assertExpression("ARRAY [1, 2][1]", new SubscriptExpression(new ArrayConstructor(ImmutableList.of(new LongLiteral("1"), new LongLiteral("2"))), new LongLiteral("1")));
    try {
        assertExpression("CASE WHEN TRUE THEN ARRAY[1,2] END[1]", null);
        fail();
    } catch (RuntimeException e) {
        // Expected
        log.error("test array subScript fail : ", e.getMessage());
    }
}
Also used : LongLiteral(io.prestosql.sql.tree.LongLiteral) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) ArrayConstructor(io.prestosql.sql.tree.ArrayConstructor) Test(org.testng.annotations.Test)

Example 4 with LongLiteral

use of io.prestosql.sql.tree.LongLiteral 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 LongLiteral

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

the class TestSqlParser method testNullIf.

@Test
public void testNullIf() {
    assertExpression("nullif(42, 87)", new NullIfExpression(new LongLiteral("42"), new LongLiteral("87")));
    assertExpression("nullif(42, null)", new NullIfExpression(new LongLiteral("42"), new NullLiteral()));
    assertExpression("nullif(null, null)", new NullIfExpression(new NullLiteral(), new NullLiteral()));
    assertInvalidExpression("nullif(1)", "Invalid number of arguments for 'nullif' function");
    assertInvalidExpression("nullif(1, 2, 3)", "Invalid number of arguments for 'nullif' function");
    assertInvalidExpression("nullif(42, 87) filter (where true)", "FILTER not valid for 'nullif' function");
    assertInvalidExpression("nullif(42, 87) OVER ()", "OVER clause not valid for 'nullif' function");
}
Also used : LongLiteral(io.prestosql.sql.tree.LongLiteral) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) NullLiteral(io.prestosql.sql.tree.NullLiteral) Test(org.testng.annotations.Test)

Aggregations

LongLiteral (io.prestosql.sql.tree.LongLiteral)56 Test (org.testng.annotations.Test)42 StringLiteral (io.prestosql.sql.tree.StringLiteral)19 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)16 Expression (io.prestosql.sql.tree.Expression)16 Identifier (io.prestosql.sql.tree.Identifier)15 FunctionCall (io.prestosql.sql.tree.FunctionCall)11 Query (io.prestosql.sql.tree.Query)11 QueryUtil.simpleQuery (io.prestosql.sql.QueryUtil.simpleQuery)10 QuerySpecification (io.prestosql.sql.tree.QuerySpecification)10 Table (io.prestosql.sql.tree.Table)10 WithQuery (io.prestosql.sql.tree.WithQuery)10 Symbol (io.prestosql.spi.plan.Symbol)9 QueryUtil.quotedIdentifier (io.prestosql.sql.QueryUtil.quotedIdentifier)9 CreateTable (io.prestosql.sql.tree.CreateTable)9 DropTable (io.prestosql.sql.tree.DropTable)9 SymbolUtils.toSymbolReference (io.prestosql.sql.planner.SymbolUtils.toSymbolReference)8 AllColumns (io.prestosql.sql.tree.AllColumns)8 Cast (io.prestosql.sql.tree.Cast)8 NotExpression (io.prestosql.sql.tree.NotExpression)8