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()));
}
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"))));
}
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());
}
}
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));
}
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");
}
Aggregations