use of io.prestosql.sql.tree.LongLiteral in project hetu-core by openlookeng.
the class TestSqlParser method testSelectWithOffset.
@Test
public void testSelectWithOffset() {
assertStatement("SELECT * FROM table1 OFFSET 2 ROWS", 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.of(new Offset("2")), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
assertStatement("SELECT * FROM table1 OFFSET 2", 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.of(new Offset("2")), 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')) OFFSET 2 ROWS", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Offset("2")), Optional.empty()));
assertStatement("SELECT * FROM (VALUES (1, '1'), (2, '2')) OFFSET 2", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Offset("2")), Optional.empty()));
}
use of io.prestosql.sql.tree.LongLiteral in project hetu-core by openlookeng.
the class TestSqlParser method testCreateSchema.
@Test
public void testCreateSchema() {
assertStatement("CREATE SCHEMA test", new CreateSchema(QualifiedName.of("test"), false, ImmutableList.of()));
assertStatement("CREATE SCHEMA IF NOT EXISTS test", new CreateSchema(QualifiedName.of("test"), true, ImmutableList.of()));
assertStatement("CREATE SCHEMA test WITH (a = 'apple', b = 123)", new CreateSchema(QualifiedName.of("test"), false, ImmutableList.of(new Property(new Identifier("a"), new StringLiteral("apple")), new Property(new Identifier("b"), new LongLiteral("123")))));
assertStatement("CREATE SCHEMA \"some name that contains space\"", new CreateSchema(QualifiedName.of("some name that contains space"), false, ImmutableList.of()));
}
use of io.prestosql.sql.tree.LongLiteral in project hetu-core by openlookeng.
the class TestSqlParser method testShowStatsForQuery.
@Test
public void testShowStatsForQuery() {
final String[] tableNames = { "t", "s.t", "c.s.t" };
for (String fullName : tableNames) {
QualifiedName qualifiedName = makeQualifiedName(fullName);
assertStatement(format("SHOW STATS FOR (SELECT * FROM %s)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.empty()));
assertStatement(format("SHOW STATS FOR (SELECT * FROM %s WHERE field > 0)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.of(new ComparisonExpression(GREATER_THAN, new Identifier("field"), new LongLiteral("0")))));
assertStatement(format("SHOW STATS FOR (SELECT * FROM %s WHERE field > 0 or field < 0)", qualifiedName), createShowStats(qualifiedName, ImmutableList.of(new AllColumns()), Optional.of(new LogicalBinaryExpression(LogicalBinaryExpression.Operator.OR, new ComparisonExpression(GREATER_THAN, new Identifier("field"), new LongLiteral("0")), new ComparisonExpression(LESS_THAN, new Identifier("field"), new LongLiteral("0"))))));
}
}
use of io.prestosql.sql.tree.LongLiteral in project hetu-core by openlookeng.
the class TestSqlParser method testIf.
@Test
public void testIf() {
assertExpression("if(true, 1, 0)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("1"), new LongLiteral("0")));
assertExpression("if(true, 3, null)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("3"), new NullLiteral()));
assertExpression("if(false, null, 4)", new IfExpression(new BooleanLiteral("false"), new NullLiteral(), new LongLiteral("4")));
assertExpression("if(false, null, null)", new IfExpression(new BooleanLiteral("false"), new NullLiteral(), new NullLiteral()));
assertExpression("if(true, 3)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("3"), null));
assertInvalidExpression("IF(true)", "Invalid number of arguments for 'if' function");
assertInvalidExpression("IF(true, 1, 0) FILTER (WHERE true)", "FILTER not valid for 'if' function");
assertInvalidExpression("IF(true, 1, 0) OVER()", "OVER clause not valid for 'if' function");
}
use of io.prestosql.sql.tree.LongLiteral in project hetu-core by openlookeng.
the class TestSqlParser method testExists.
@Test
public void testExists() {
assertStatement("SELECT EXISTS(SELECT 1)", simpleQuery(selectList(exists(simpleQuery(selectList(new LongLiteral("1")))))));
assertStatement("SELECT EXISTS(SELECT 1) = EXISTS(SELECT 2)", simpleQuery(selectList(new ComparisonExpression(ComparisonExpression.Operator.EQUAL, exists(simpleQuery(selectList(new LongLiteral("1")))), exists(simpleQuery(selectList(new LongLiteral("2"))))))));
assertStatement("SELECT NOT EXISTS(SELECT 1) = EXISTS(SELECT 2)", simpleQuery(selectList(new NotExpression(new ComparisonExpression(ComparisonExpression.Operator.EQUAL, exists(simpleQuery(selectList(new LongLiteral("1")))), exists(simpleQuery(selectList(new LongLiteral("2")))))))));
assertStatement("SELECT (NOT EXISTS(SELECT 1)) = EXISTS(SELECT 2)", simpleQuery(selectList(new ComparisonExpression(ComparisonExpression.Operator.EQUAL, new NotExpression(exists(simpleQuery(selectList(new LongLiteral("1"))))), exists(simpleQuery(selectList(new LongLiteral("2"))))))));
}
Aggregations