use of io.trino.sql.tree.LongLiteral in project trino by trinodb.
the class TestPushPredicateIntoTableScan method doesNotFireOnNonDeterministicPredicate.
@Test
public void doesNotFireOnNonDeterministicPredicate() {
ColumnHandle columnHandle = new TpchColumnHandle("nationkey", BIGINT);
tester().assertThat(pushPredicateIntoTableScan).on(p -> p.filter(new ComparisonExpression(EQUAL, functionResolution.functionCallBuilder(QualifiedName.of("rand")).build(), new LongLiteral("42")), p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), columnHandle), TupleDomain.all()))).doesNotFire();
}
use of io.trino.sql.tree.LongLiteral in project trino by trinodb.
the class TestPushProjectionIntoTableScan method testDoesNotFire.
@Test
public void testDoesNotFire() {
try (RuleTester ruleTester = defaultRuleTester()) {
String columnName = "input_column";
Type columnType = ROW_TYPE;
ColumnHandle inputColumnHandle = column(columnName, columnType);
MockConnectorFactory factory = createMockFactory(ImmutableMap.of(columnName, inputColumnHandle), Optional.empty());
ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, factory, ImmutableMap.of());
PushProjectionIntoTableScan optimizer = createRule(ruleTester);
ruleTester.assertThat(optimizer).on(p -> {
Symbol symbol = p.symbol(columnName, columnType);
return p.project(Assignments.of(p.symbol("symbol_dereference", BIGINT), new SubscriptExpression(symbol.toSymbolReference(), new LongLiteral("1"))), p.tableScan(TEST_TABLE_HANDLE, ImmutableList.of(symbol), ImmutableMap.of(symbol, inputColumnHandle)));
}).withSession(MOCK_SESSION).doesNotFire();
}
}
use of io.trino.sql.tree.LongLiteral in project trino by trinodb.
the class TestPushProjectionThroughExchange method testSkipIdentityProjectionIfOutputPresent.
@Test
public void testSkipIdentityProjectionIfOutputPresent() {
// In the following example, the Projection over Exchange has got an identity assignment (a -> a).
// The Projection is pushed down to Exchange's source, and the identity assignment is translated into
// a0 -> a. The assignment is added to the pushed-down Projection because the input symbol 'a' is
// required by the Exchange as a partitioning symbol.
// When all the assignments from the parent Projection are added to the pushed-down Projection,
// this assignment is omitted. Otherwise the doubled assignment would cause an error.
tester().assertThat(new PushProjectionThroughExchange()).on(p -> {
Symbol a = p.symbol("a");
Symbol aTimes5 = p.symbol("a_times_5");
return p.project(Assignments.of(aTimes5, new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.MULTIPLY, new SymbolReference("a"), new LongLiteral("5")), a, a.toSymbolReference()), p.exchange(e -> e.addSource(p.values(a)).addInputsSet(a).fixedHashDistributionParitioningScheme(ImmutableList.of(a), ImmutableList.of(a))));
}).matches(exchange(strictProject(ImmutableMap.of("a_0", expression("a"), "a_times_5", expression("a * 5")), values(ImmutableList.of("a")))));
// In the following example, the Projection over Exchange has got an identity assignment (b -> b).
// The Projection is pushed down to Exchange's source, and the identity assignment is translated into
// a0 -> a. The assignment is added to the pushed-down Projection because the input symbol 'a' is
// required by the Exchange as a partitioning symbol.
// When all the assignments from the parent Projection are added to the pushed-down Projection,
// this assignment is omitted. Otherwise the doubled assignment would cause an error.
tester().assertThat(new PushProjectionThroughExchange()).on(p -> {
Symbol a = p.symbol("a");
Symbol bTimes5 = p.symbol("b_times_5");
Symbol b = p.symbol("b");
return p.project(Assignments.of(bTimes5, new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.MULTIPLY, new SymbolReference("b"), new LongLiteral("5")), b, b.toSymbolReference()), p.exchange(e -> e.addSource(p.values(a)).addInputsSet(a).fixedHashDistributionParitioningScheme(ImmutableList.of(b), ImmutableList.of(b))));
}).matches(exchange(strictProject(ImmutableMap.of("a_0", expression("a"), "a_times_5", expression("a * 5")), values(ImmutableList.of("a")))));
}
use of io.trino.sql.tree.LongLiteral in project trino by trinodb.
the class TestPushLimitThroughProject method testPushDownLimitThroughOverlappingDereferences.
@Test
public void testPushDownLimitThroughOverlappingDereferences() {
RowType rowType = RowType.from(ImmutableList.of(new RowType.Field(Optional.of("x"), BIGINT), new RowType.Field(Optional.of("y"), BIGINT)));
tester().assertThat(new PushLimitThroughProject(tester().getTypeAnalyzer())).on(p -> {
Symbol a = p.symbol("a", rowType);
return p.limit(1, p.project(Assignments.of(p.symbol("b"), new SubscriptExpression(a.toSymbolReference(), new LongLiteral("1")), p.symbol("c", rowType), a.toSymbolReference()), p.values(a)));
}).matches(project(ImmutableMap.of("b", expression("a[1]"), "c", expression("a")), limit(1, values("a"))));
}
use of io.trino.sql.tree.LongLiteral in project trino by trinodb.
the class TestRemoveUnreferencedScalarSubqueries method testDoNotRemoveInputOfLeftOrFullJoinWhenSubqueryPotentiallyEmpty.
@Test
public void testDoNotRemoveInputOfLeftOrFullJoinWhenSubqueryPotentiallyEmpty() {
tester().assertThat(new RemoveUnreferencedScalarSubqueries()).on(p -> {
Symbol b = p.symbol("b");
return p.correlatedJoin(emptyList(), p.values(emptyList(), ImmutableList.of(emptyList())), LEFT, TRUE_LITERAL, p.filter(new ComparisonExpression(LESS_THAN, b.toSymbolReference(), new LongLiteral("3")), p.values(2, b)));
}).doesNotFire();
tester().assertThat(new RemoveUnreferencedScalarSubqueries()).on(p -> {
Symbol b = p.symbol("b");
return p.correlatedJoin(emptyList(), p.values(emptyList(), ImmutableList.of(emptyList())), FULL, TRUE_LITERAL, p.filter(new ComparisonExpression(LESS_THAN, b.toSymbolReference(), new LongLiteral("3")), p.values(2, b)));
}).doesNotFire();
}
Aggregations