Search in sources :

Example 16 with LongLiteral

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

the class TestSqlParser method testSelectWithFetch.

@Test
public void testSelectWithFetch() {
    assertStatement("SELECT * FROM table1 FETCH FIRST 2 ROWS ONLY", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst("2"))), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 FETCH NEXT ROW ONLY", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst(Optional.empty()))), Optional.empty(), Optional.empty(), Optional.empty()));
    Query valuesQuery = query(values(row(new LongLiteral("1"), new StringLiteral("1")), row(new LongLiteral("2"), new StringLiteral("2"))));
    assertStatement("SELECT * FROM (VALUES (1, '1'), (2, '2')) FETCH FIRST ROW ONLY", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst(Optional.empty()))));
    assertStatement("SELECT * FROM (VALUES (1, '1'), (2, '2')) FETCH FIRST ROW WITH TIES", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst(Optional.empty(), true))));
    assertStatement("SELECT * FROM table1 FETCH FIRST 2 ROWS WITH TIES", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst("2", true))), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 FETCH NEXT ROW WITH TIES", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new FetchFirst(Optional.empty(), true))), Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : QuerySpecification(io.prestosql.sql.tree.QuerySpecification) 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) QueryUtil.simpleQuery(io.prestosql.sql.QueryUtil.simpleQuery) Query(io.prestosql.sql.tree.Query) WithQuery(io.prestosql.sql.tree.WithQuery) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) AllColumns(io.prestosql.sql.tree.AllColumns) FetchFirst(io.prestosql.sql.tree.FetchFirst) Test(org.testng.annotations.Test)

Example 17 with LongLiteral

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

the class TestSqlParser method testSelectWithRowType.

@Test
public void testSelectWithRowType() {
    assertStatement("SELECT col1.f1, col2, col3.f1.f2.f3 FROM table1", new Query(Optional.empty(), new QuerySpecification(selectList(new DereferenceExpression(new Identifier("col1"), identifier("f1")), new Identifier("col2"), new DereferenceExpression(new DereferenceExpression(new DereferenceExpression(new Identifier("col3"), identifier("f1")), identifier("f2")), identifier("f3"))), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT col1.f1[0], col2, col3[2].f2.f3, col4[4] FROM table1", new Query(Optional.empty(), new QuerySpecification(selectList(new SubscriptExpression(new DereferenceExpression(new Identifier("col1"), identifier("f1")), new LongLiteral("0")), new Identifier("col2"), new DereferenceExpression(new DereferenceExpression(new SubscriptExpression(new Identifier("col3"), new LongLiteral("2")), identifier("f2")), identifier("f3")), new SubscriptExpression(new Identifier("col4"), new LongLiteral("4"))), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT CAST(ROW(11, 12) AS ROW(COL0 INTEGER, COL1 INTEGER)).col0", new Query(Optional.empty(), new QuerySpecification(selectList(new DereferenceExpression(new Cast(new Row(Lists.newArrayList(new LongLiteral("11"), new LongLiteral("12"))), "ROW(COL0 INTEGER,COL1 INTEGER)"), identifier("col0"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : Cast(io.prestosql.sql.tree.Cast) QuerySpecification(io.prestosql.sql.tree.QuerySpecification) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) 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) 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) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) Row(io.prestosql.sql.tree.Row) Test(org.testng.annotations.Test)

Example 18 with LongLiteral

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

the class TestSqlParser method testCall.

@Test
public void testCall() {
    assertStatement("CALL foo()", new Call(QualifiedName.of("foo"), ImmutableList.of()));
    assertStatement("CALL foo(123, a => 1, b => 'go', 456)", new Call(QualifiedName.of("foo"), ImmutableList.of(new CallArgument(new LongLiteral("123")), new CallArgument("a", new LongLiteral("1")), new CallArgument("b", new StringLiteral("go")), new CallArgument(new LongLiteral("456")))));
}
Also used : Call(io.prestosql.sql.tree.Call) FunctionCall(io.prestosql.sql.tree.FunctionCall) CallArgument(io.prestosql.sql.tree.CallArgument) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) Test(org.testng.annotations.Test)

Example 19 with LongLiteral

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

the class TestSqlParser method testCreateCube.

@Test
public void testCreateCube() {
    assertStatement("CREATE CUBE foo ON bar WITH (AGGREGATIONS=(count(c)), GROUP = (a, b)) WHERE d1 > 10", new CreateCube(QualifiedName.of("foo"), QualifiedName.of("bar"), ImmutableList.of(new Identifier("a"), new Identifier("b")), ImmutableSet.of(new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new Identifier("c")))), false, ImmutableList.of(), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("d1"), new LongLiteral("10"))), null));
    assertStatement("CREATE CUBE foo ON bar WITH (AGGREGATIONS=(count(distinct c), sum(e)), GROUP = (a, b), FILTER = (f between 1 and 10)) WHERE d1 > 10", new CreateCube(QualifiedName.of("foo"), QualifiedName.of("bar"), ImmutableList.of(new Identifier("a"), new Identifier("b")), ImmutableSet.of(new FunctionCall(QualifiedName.of("count"), true, ImmutableList.of(new Identifier("c"))), new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(new Identifier("e")))), false, ImmutableList.of(), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("d1"), new LongLiteral("10"))), new BetweenPredicate(new Identifier("f"), new LongLiteral("1"), new LongLiteral("10"))));
    assertStatement("CREATE CUBE foo ON bar WITH (AGGREGATIONS=(count(c), sum(d), avg(e)), GROUP = (a, b)) WHERE d1 > 10", new CreateCube(QualifiedName.of("foo"), QualifiedName.of("bar"), ImmutableList.of(new Identifier("a"), new Identifier("b")), ImmutableSet.of(new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new Identifier("c"))), new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(new Identifier("d"))), new FunctionCall(QualifiedName.of("avg"), ImmutableList.of(new Identifier("e"))), new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(new Identifier("e"))), new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new Identifier("e")))), false, ImmutableList.of(), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("d1"), new LongLiteral("10"))), null));
    assertStatement("CREATE CUBE avgtestcube ON bar WITH (AGGREGATIONS=(count(c), sum(d), avg(e), avg(f)), GROUP = (a, b)) WHERE d1 > 10", new CreateCube(QualifiedName.of("avgtestcube"), QualifiedName.of("bar"), ImmutableList.of(new Identifier("a"), new Identifier("b")), ImmutableSet.of(new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new Identifier("c"))), new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(new Identifier("d"))), new FunctionCall(QualifiedName.of("avg"), ImmutableList.of(new Identifier("e"))), new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(new Identifier("e"))), new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new Identifier("e"))), new FunctionCall(QualifiedName.of("avg"), ImmutableList.of(new Identifier("f"))), new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(new Identifier("f"))), new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new Identifier("f")))), false, ImmutableList.of(), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("d1"), new LongLiteral("10"))), null));
    assertStatement("CREATE CUBE c1.s1.foo ON c2.s2.bar WITH (AGGREGATIONS=(count(c)), GROUP = (a, b)) WHERE d1 > 10", new CreateCube(QualifiedName.of("c1", "s1", "foo"), QualifiedName.of("c2", "s2", "bar"), ImmutableList.of(new Identifier("a"), new Identifier("b")), ImmutableSet.of(new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new Identifier("c")))), false, ImmutableList.of(), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("d1"), new LongLiteral("10"))), null));
    assertStatement("CREATE CUBE IF NOT EXISTS foo ON bar WITH (AGGREGATIONS=(count(c)), GROUP = (a, b)) WHERE d1 > 10", new CreateCube(QualifiedName.of("foo"), QualifiedName.of("bar"), ImmutableList.of(new Identifier("a"), new Identifier("b")), ImmutableSet.of(new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new Identifier("c")))), true, ImmutableList.of(), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("d1"), new LongLiteral("10"))), null));
    assertStatement("CREATE CUBE IF NOT EXISTS foo ON bar WITH (AGGREGATIONS=(count(c)), GROUP = (a, b), format = 'ORC', partitioned_by = ARRAY[ 'd' ]) WHERE d1 > 10", new CreateCube(QualifiedName.of("foo"), QualifiedName.of("bar"), ImmutableList.of(new Identifier("a"), new Identifier("b")), ImmutableSet.of(new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new Identifier("c")))), true, ImmutableList.of(new Property(new Identifier("format"), new StringLiteral("ORC")), new Property(new Identifier("partitioned_by"), new ArrayConstructor(ImmutableList.of(new StringLiteral("d"))))), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("d1"), new LongLiteral("10"))), null));
    assertStatement("CREATE CUBE IF NOT EXISTS foo ON bar WITH (AGGREGATIONS=(count(c)), GROUP = (a, b), format = 'ORC', partitioned_by = ARRAY[ 'd' ], FILTER = (d2 > 20)) WHERE d1 > 10", new CreateCube(QualifiedName.of("foo"), QualifiedName.of("bar"), ImmutableList.of(new Identifier("a"), new Identifier("b")), ImmutableSet.of(new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new Identifier("c")))), true, ImmutableList.of(new Property(new Identifier("format"), new StringLiteral("ORC")), new Property(new Identifier("partitioned_by"), new ArrayConstructor(ImmutableList.of(new StringLiteral("d"))))), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("d1"), new LongLiteral("10"))), new ComparisonExpression(GREATER_THAN, new Identifier("d2"), new LongLiteral("20"))));
}
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) BetweenPredicate(io.prestosql.sql.tree.BetweenPredicate) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) CreateCube(io.prestosql.sql.tree.CreateCube) ArrayConstructor(io.prestosql.sql.tree.ArrayConstructor) FunctionCall(io.prestosql.sql.tree.FunctionCall) Property(io.prestosql.sql.tree.Property) Test(org.testng.annotations.Test)

Example 20 with LongLiteral

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

the class TestSqlParser method testPrecedenceAndAssociativity.

@Test
public void testPrecedenceAndAssociativity() {
    assertExpression("1 AND 2 OR 3", new LogicalBinaryExpression(LogicalBinaryExpression.Operator.OR, new LogicalBinaryExpression(LogicalBinaryExpression.Operator.AND, new LongLiteral("1"), new LongLiteral("2")), new LongLiteral("3")));
    assertExpression("1 OR 2 AND 3", new LogicalBinaryExpression(LogicalBinaryExpression.Operator.OR, new LongLiteral("1"), new LogicalBinaryExpression(LogicalBinaryExpression.Operator.AND, new LongLiteral("2"), new LongLiteral("3"))));
    assertExpression("NOT 1 AND 2", new LogicalBinaryExpression(LogicalBinaryExpression.Operator.AND, new NotExpression(new LongLiteral("1")), new LongLiteral("2")));
    assertExpression("NOT 1 OR 2", new LogicalBinaryExpression(LogicalBinaryExpression.Operator.OR, new NotExpression(new LongLiteral("1")), new LongLiteral("2")));
    assertExpression("-1 + 2", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.ADD, new LongLiteral("-1"), new LongLiteral("2")));
    assertExpression("1 - 2 - 3", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.SUBTRACT, new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.SUBTRACT, new LongLiteral("1"), new LongLiteral("2")), new LongLiteral("3")));
    assertExpression("1 / 2 / 3", new ArithmeticBinaryExpression(DIVIDE, new ArithmeticBinaryExpression(DIVIDE, new LongLiteral("1"), new LongLiteral("2")), new LongLiteral("3")));
    assertExpression("1 + 2 * 3", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.ADD, new LongLiteral("1"), new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.MULTIPLY, new LongLiteral("2"), new LongLiteral("3"))));
}
Also used : LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) LongLiteral(io.prestosql.sql.tree.LongLiteral) NotExpression(io.prestosql.sql.tree.NotExpression) 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