Search in sources :

Example 1 with FunctionCall

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

the class TestSqlParser method testAggregationWithOrderBy.

@Test
public void testAggregationWithOrderBy() {
    assertExpression("array_agg(x ORDER BY x DESC)", new FunctionCall(QualifiedName.of("array_agg"), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(identifier("x"), DESCENDING, UNDEFINED)))), false, ImmutableList.of(identifier("x"))));
    assertStatement("SELECT array_agg(x ORDER BY t.y) FROM t", new Query(Optional.empty(), new QuerySpecification(selectList(new FunctionCall(QualifiedName.of("array_agg"), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(new DereferenceExpression(new Identifier("t"), identifier("y")), ASCENDING, UNDEFINED)))), false, ImmutableList.of(new Identifier("x")))), Optional.of(table(QualifiedName.of("t"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : OrderBy(io.prestosql.sql.tree.OrderBy) QuerySpecification(io.prestosql.sql.tree.QuerySpecification) SortItem(io.prestosql.sql.tree.SortItem) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) 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) FunctionCall(io.prestosql.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 2 with FunctionCall

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

the class TestSqlParser method testPosition.

@Test
public void testPosition() {
    assertExpression("position('a' in 'b')", new FunctionCall(QualifiedName.of("strpos"), ImmutableList.of(new StringLiteral("b"), new StringLiteral("a"))));
    assertExpression("position('a' in ('b'))", new FunctionCall(QualifiedName.of("strpos"), ImmutableList.of(new StringLiteral("b"), new StringLiteral("a"))));
}
Also used : StringLiteral(io.prestosql.sql.tree.StringLiteral) FunctionCall(io.prestosql.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 3 with FunctionCall

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

the class TestSqlParser method testSubstringRegisteredFunction.

@Test
public void testSubstringRegisteredFunction() {
    final String givenString = "ABCDEF";
    assertStatement(format("SELECT substring('%s', 2)", givenString), new Query(Optional.empty(), new QuerySpecification(selectList(new FunctionCall(QualifiedName.of("substring"), Lists.newArrayList(new StringLiteral(givenString), new LongLiteral("2")))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement(format("SELECT substring('%s', 2, 3)", givenString), new Query(Optional.empty(), new QuerySpecification(selectList(new FunctionCall(QualifiedName.of("substring"), Lists.newArrayList(new StringLiteral(givenString), new LongLiteral("2"), new LongLiteral("3")))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : QuerySpecification(io.prestosql.sql.tree.QuerySpecification) 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) FunctionCall(io.prestosql.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 4 with FunctionCall

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

the class TestSqlParser method testCreateTableAsSelect.

@Test
public void testCreateTableAsSelect() {
    Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t")));
    Query querySelectColumn = simpleQuery(selectList(new Identifier("a")), table(QualifiedName.of("t")));
    Query querySelectColumns = simpleQuery(selectList(new Identifier("a"), new Identifier("b")), table(QualifiedName.of("t")));
    QualifiedName table = QualifiedName.of("foo");
    assertStatement("CREATE TABLE foo AS SELECT * FROM t", new CreateTableAsSelect(table, query, false, ImmutableList.of(), true, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE foo(x) AS SELECT a FROM t", new CreateTableAsSelect(table, querySelectColumn, false, ImmutableList.of(), true, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE foo(x,y) AS SELECT a,b FROM t", new CreateTableAsSelect(table, querySelectColumns, false, ImmutableList.of(), true, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS foo AS SELECT * FROM t", new CreateTableAsSelect(table, query, true, ImmutableList.of(), true, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS foo(x) AS SELECT a FROM t", new CreateTableAsSelect(table, querySelectColumn, true, ImmutableList.of(), true, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS foo(x,y) AS SELECT a,b FROM t", new CreateTableAsSelect(table, querySelectColumns, true, ImmutableList.of(), true, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    assertStatement("CREATE TABLE foo AS SELECT * FROM t WITH NO DATA", new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE foo(x) AS SELECT a FROM t WITH NO DATA", new CreateTableAsSelect(table, querySelectColumn, false, ImmutableList.of(), false, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE foo(x,y) AS SELECT a,b FROM t WITH NO DATA", new CreateTableAsSelect(table, querySelectColumns, false, ImmutableList.of(), false, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    List<Property> properties = ImmutableList.of(new Property(new Identifier("string"), new StringLiteral("bar")), new Property(new Identifier("long"), new LongLiteral("42")), new Property(new Identifier("computed"), new FunctionCall(QualifiedName.of("concat"), ImmutableList.of(new StringLiteral("ban"), new StringLiteral("ana")))), new Property(new Identifier("a"), new ArrayConstructor(ImmutableList.of(new StringLiteral("v1"), new StringLiteral("v2")))));
    assertStatement("CREATE TABLE foo " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT * FROM t", new CreateTableAsSelect(table, query, false, properties, true, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE foo(x) " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a FROM t", new CreateTableAsSelect(table, querySelectColumn, false, properties, true, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE foo(x,y) " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a,b FROM t", new CreateTableAsSelect(table, querySelectColumns, false, properties, true, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    assertStatement("CREATE TABLE foo " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT * FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, query, false, properties, false, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE foo(x) " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumn, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE foo(x,y) " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a,b FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumns, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    assertStatement("CREATE TABLE foo COMMENT 'test'" + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT * FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, query, false, properties, false, Optional.empty(), Optional.of("test")));
    assertStatement("CREATE TABLE foo(x) COMMENT 'test'" + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumn, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.of("test")));
    assertStatement("CREATE TABLE foo(x,y) COMMENT 'test'" + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a,b FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumns, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.of("test")));
    assertStatement("CREATE TABLE foo(x,y) COMMENT 'test'" + "WITH ( \"string\" = 'bar', \"long\" = 42, computed = 'ban' || 'ana', a = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a,b FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumns, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.of("test")));
}
Also used : 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) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) QualifiedName(io.prestosql.sql.tree.QualifiedName) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) ArrayConstructor(io.prestosql.sql.tree.ArrayConstructor) AllColumns(io.prestosql.sql.tree.AllColumns) FunctionCall(io.prestosql.sql.tree.FunctionCall) Property(io.prestosql.sql.tree.Property) Test(org.testng.annotations.Test)

Example 5 with FunctionCall

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

Aggregations

FunctionCall (io.prestosql.sql.tree.FunctionCall)33 StringLiteral (io.prestosql.sql.tree.StringLiteral)15 Test (org.testng.annotations.Test)15 Expression (io.prestosql.sql.tree.Expression)14 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)13 Identifier (io.prestosql.sql.tree.Identifier)13 LongLiteral (io.prestosql.sql.tree.LongLiteral)11 QualifiedName (io.prestosql.sql.tree.QualifiedName)10 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)9 IfExpression (io.prestosql.sql.tree.IfExpression)8 InListExpression (io.prestosql.sql.tree.InListExpression)8 LambdaExpression (io.prestosql.sql.tree.LambdaExpression)8 QuantifiedComparisonExpression (io.prestosql.sql.tree.QuantifiedComparisonExpression)8 QuerySpecification (io.prestosql.sql.tree.QuerySpecification)8 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)7 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)7 NotExpression (io.prestosql.sql.tree.NotExpression)7 OrderBy (io.prestosql.sql.tree.OrderBy)7 SortItem (io.prestosql.sql.tree.SortItem)7 SubqueryExpression (io.prestosql.sql.tree.SubqueryExpression)7