Search in sources :

Example 6 with StringLiteral

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

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

the class TestSqlParser method testValues.

@Test
public void testValues() {
    Query valuesQuery = query(values(row(new StringLiteral("a"), new LongLiteral("1"), new DoubleLiteral("2.2")), row(new StringLiteral("b"), new LongLiteral("2"), new DoubleLiteral("3.3"))));
    assertStatement("VALUES ('a', 1, 2.2e0), ('b', 2, 3.3e0)", valuesQuery);
    assertStatement("SELECT * FROM (VALUES ('a', 1, 2.2e0), ('b', 2, 3.3e0))", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery)));
}
Also used : 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) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) AllColumns(io.prestosql.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Example 8 with StringLiteral

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

the class TestSqlParser method testFormat.

@Test
public void testFormat() {
    assertExpression("format('%s', 'abc')", new Format(ImmutableList.of(new StringLiteral("%s"), new StringLiteral("abc"))));
    assertExpression("format('%d %s', 123, 'x')", new Format(ImmutableList.of(new StringLiteral("%d %s"), new LongLiteral("123"), new StringLiteral("x"))));
    assertInvalidExpression("format()", "The 'format' function must have at least two arguments");
    assertInvalidExpression("format('%s')", "The 'format' function must have at least two arguments");
}
Also used : ExplainFormat(io.prestosql.sql.tree.ExplainFormat) Format(io.prestosql.sql.tree.Format) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) Test(org.testng.annotations.Test)

Example 9 with StringLiteral

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

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

Aggregations

StringLiteral (io.prestosql.sql.tree.StringLiteral)47 Test (org.testng.annotations.Test)23 LongLiteral (io.prestosql.sql.tree.LongLiteral)20 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)15 FunctionCall (io.prestosql.sql.tree.FunctionCall)15 Identifier (io.prestosql.sql.tree.Identifier)15 Expression (io.prestosql.sql.tree.Expression)14 Property (io.prestosql.sql.tree.Property)12 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)9 ArithmeticUnaryExpression (io.prestosql.sql.tree.ArithmeticUnaryExpression)9 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)9 DoubleLiteral (io.prestosql.sql.tree.DoubleLiteral)9 IfExpression (io.prestosql.sql.tree.IfExpression)9 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)9 NotExpression (io.prestosql.sql.tree.NotExpression)9 QuantifiedComparisonExpression (io.prestosql.sql.tree.QuantifiedComparisonExpression)9 SearchedCaseExpression (io.prestosql.sql.tree.SearchedCaseExpression)9 SimpleCaseExpression (io.prestosql.sql.tree.SimpleCaseExpression)9 SubqueryExpression (io.prestosql.sql.tree.SubqueryExpression)9 CoalesceExpression (io.prestosql.sql.tree.CoalesceExpression)8