use of com.facebook.presto.sql.tree.ArrayConstructor in project presto by prestodb.
the class TestSqlParser method testArrayConstructor.
@Test
public void testArrayConstructor() throws Exception {
assertExpression("ARRAY []", new ArrayConstructor(ImmutableList.of()));
assertExpression("ARRAY [1, 2]", new ArrayConstructor(ImmutableList.of(new LongLiteral("1"), new LongLiteral("2"))));
assertExpression("ARRAY [1.0, 2.5]", 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 com.facebook.presto.sql.tree.ArrayConstructor in project presto by prestodb.
the class TestSqlParser method testCreateTableAsSelect.
@Test
public void testCreateTableAsSelect() throws Exception {
Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t")));
QualifiedName table = QualifiedName.of("foo");
assertStatement("CREATE TABLE foo AS SELECT * FROM t", new CreateTableAsSelect(table, query, false, ImmutableMap.of(), true));
assertStatement("CREATE TABLE IF NOT EXISTS foo AS SELECT * FROM t", new CreateTableAsSelect(table, query, true, ImmutableMap.of(), true));
assertStatement("CREATE TABLE foo AS SELECT * FROM t WITH NO DATA", new CreateTableAsSelect(table, query, false, ImmutableMap.of(), false));
ImmutableMap<String, Expression> properties = ImmutableMap.<String, Expression>builder().put("string", new StringLiteral("bar")).put("long", new LongLiteral("42")).put("computed", new FunctionCall(QualifiedName.of("concat"), ImmutableList.of(new StringLiteral("ban"), new StringLiteral("ana")))).put("a", new ArrayConstructor(ImmutableList.of(new StringLiteral("v1"), new StringLiteral("v2")))).build();
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));
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));
}
use of com.facebook.presto.sql.tree.ArrayConstructor in project presto by prestodb.
the class TestSqlParser method testArraySubscript.
@Test
public void testArraySubscript() throws Exception {
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
}
}
use of com.facebook.presto.sql.tree.ArrayConstructor in project presto by prestodb.
the class TestEqualityInference method testExpressionsThatMayReturnNullOnNonNullInput.
@Test
public void testExpressionsThatMayReturnNullOnNonNullInput() throws Exception {
List<Expression> candidates = ImmutableList.of(// try_cast
new Cast(nameReference("b"), "BIGINT", true), new FunctionCall(QualifiedName.of("try"), ImmutableList.of(nameReference("b"))), new NullIfExpression(nameReference("b"), number(1)), new IfExpression(nameReference("b"), number(1), new NullLiteral()), new DereferenceExpression(nameReference("b"), "x"), new InPredicate(nameReference("b"), new InListExpression(ImmutableList.of(new NullLiteral()))), new SearchedCaseExpression(ImmutableList.of(new WhenClause(new IsNotNullPredicate(nameReference("b")), new NullLiteral())), Optional.empty()), new SimpleCaseExpression(nameReference("b"), ImmutableList.of(new WhenClause(number(1), new NullLiteral())), Optional.empty()), new SubscriptExpression(new ArrayConstructor(ImmutableList.of(new NullLiteral())), nameReference("b")));
for (Expression candidate : candidates) {
EqualityInference.Builder builder = new EqualityInference.Builder();
builder.extractInferenceCandidates(equals(nameReference("b"), nameReference("x")));
builder.extractInferenceCandidates(equals(nameReference("a"), candidate));
EqualityInference inference = builder.build();
List<Expression> equalities = inference.generateEqualitiesPartitionedBy(matchesSymbols("b")).getScopeStraddlingEqualities();
assertEquals(equalities.size(), 1);
assertTrue(equalities.get(0).equals(equals(nameReference("x"), nameReference("b"))) || equalities.get(0).equals(equals(nameReference("b"), nameReference("x"))));
}
}
Aggregations