use of io.trino.sql.tree.CharLiteral in project trino by trinodb.
the class TestMergeProjectWithValues method testMergeProjectWithValues.
@Test
public void testMergeProjectWithValues() {
tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> {
Symbol a = p.symbol("a");
Symbol b = p.symbol("b");
Symbol c = p.symbol("c");
Symbol d = p.symbol("d");
Symbol e = p.symbol("e");
Symbol f = p.symbol("f");
Assignments.Builder assignments = Assignments.builder();
// identity assignment
assignments.putIdentity(a);
// renaming assignment
assignments.put(d, b.toSymbolReference());
// expression involving input symbol
assignments.put(e, new IsNullPredicate(a.toSymbolReference()));
// constant expression
assignments.put(f, new LongLiteral("1"));
return p.project(assignments.build(), p.valuesOfExpressions(ImmutableList.of(a, b, c), ImmutableList.of(new Row(ImmutableList.of(new CharLiteral("x"), new BooleanLiteral("true"), new LongLiteral("1"))), new Row(ImmutableList.of(new CharLiteral("y"), new BooleanLiteral("false"), new LongLiteral("2"))), new Row(ImmutableList.of(new CharLiteral("z"), new BooleanLiteral("true"), new LongLiteral("3"))))));
}).matches(values(ImmutableList.of("a", "d", "e", "f"), ImmutableList.of(ImmutableList.of(new CharLiteral("x"), new BooleanLiteral("true"), new IsNullPredicate(new CharLiteral("x")), new LongLiteral("1")), ImmutableList.of(new CharLiteral("y"), new BooleanLiteral("false"), new IsNullPredicate(new CharLiteral("y")), new LongLiteral("1")), ImmutableList.of(new CharLiteral("z"), new BooleanLiteral("true"), new IsNullPredicate(new CharLiteral("z")), new LongLiteral("1")))));
// ValuesNode has no rows
tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> {
Symbol a = p.symbol("a");
Symbol b = p.symbol("b");
Symbol c = p.symbol("c");
Symbol d = p.symbol("d");
Symbol e = p.symbol("e");
Symbol f = p.symbol("f");
Assignments.Builder assignments = Assignments.builder();
// identity assignment
assignments.putIdentity(a);
// renaming assignment
assignments.put(d, b.toSymbolReference());
// expression involving input symbol
assignments.put(e, new IsNullPredicate(a.toSymbolReference()));
// constant expression
assignments.put(f, new LongLiteral("1"));
return p.project(assignments.build(), p.values(ImmutableList.of(a, b, c), ImmutableList.of()));
}).matches(values(ImmutableList.of("a", "d", "e", "f"), ImmutableList.of()));
}
use of io.trino.sql.tree.CharLiteral in project trino by trinodb.
the class TestMergeProjectWithValues method testProjectWithoutOutputSymbols.
@Test
public void testProjectWithoutOutputSymbols() {
// ValuesNode has two output symbols and two rows
tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> p.project(Assignments.of(), p.valuesOfExpressions(ImmutableList.of(p.symbol("a"), p.symbol("b")), ImmutableList.of(new Row(ImmutableList.of(new CharLiteral("x"), new BooleanLiteral("true"))), new Row(ImmutableList.of(new CharLiteral("y"), new BooleanLiteral("false"))))))).matches(values(2));
// ValuesNode has no output symbols and two rows
tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> p.project(Assignments.of(), p.values(ImmutableList.of(), ImmutableList.of(ImmutableList.of(), ImmutableList.of())))).matches(values(2));
// ValuesNode has two output symbols and no rows
tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> p.project(Assignments.of(), p.values(ImmutableList.of(p.symbol("a"), p.symbol("b")), ImmutableList.of()))).matches(values());
// ValuesNode has no output symbols and no rows
tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> p.project(Assignments.of(), p.values(ImmutableList.of(), ImmutableList.of()))).matches(values());
}
use of io.trino.sql.tree.CharLiteral in project trino by trinodb.
the class TestSqlParser method testLiterals.
@Test
public void testLiterals() {
assertExpression("TIME 'abc'", new TimeLiteral("abc"));
assertExpression("TIMESTAMP 'abc'", new TimestampLiteral("abc"));
assertExpression("INTERVAL '33' day", new IntervalLiteral("33", Sign.POSITIVE, IntervalField.DAY, Optional.empty()));
assertExpression("INTERVAL '33' day to second", new IntervalLiteral("33", Sign.POSITIVE, IntervalField.DAY, Optional.of(IntervalField.SECOND)));
assertExpression("CHAR 'abc'", new CharLiteral("abc"));
}
Aggregations