use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.
the class TestPushJoinIntoTableScan method testPushJoinIntoTableRequiresFullColumnHandleMappingInResult.
@Test
public void testPushJoinIntoTableRequiresFullColumnHandleMappingInResult() {
try (RuleTester ruleTester = defaultRuleTester()) {
MockConnectorFactory connectorFactory = createMockConnectorFactory((session, applyJoinType, left, right, joinConditions, leftAssignments, rightAssignments) -> Optional.of(new JoinApplicationResult<>(JOIN_CONNECTOR_TABLE_HANDLE, ImmutableMap.of(COLUMN_A1_HANDLE, JOIN_COLUMN_A1_HANDLE, COLUMN_A2_HANDLE, JOIN_COLUMN_A2_HANDLE), // mapping for COLUMN_B1_HANDLE is missing
ImmutableMap.of(), false)));
ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, connectorFactory, ImmutableMap.of());
assertThatThrownBy(() -> {
ruleTester.assertThat(new PushJoinIntoTableScan(ruleTester.getMetadata())).on(p -> {
Symbol columnA1Symbol = p.symbol(COLUMN_A1);
Symbol columnA2Symbol = p.symbol(COLUMN_A2);
Symbol columnB1Symbol = p.symbol(COLUMN_B1);
TupleDomain<ColumnHandle> leftContraint = TupleDomain.fromFixedValues(ImmutableMap.of(COLUMN_A2_HANDLE, NullableValue.of(BIGINT, 44L)));
TupleDomain<ColumnHandle> rightConstraint = TupleDomain.fromFixedValues(ImmutableMap.of(COLUMN_B1_HANDLE, NullableValue.of(BIGINT, 45L)));
TableScanNode left = p.tableScan(TABLE_A_HANDLE, ImmutableList.of(columnA1Symbol, columnA2Symbol), ImmutableMap.of(columnA1Symbol, COLUMN_A1_HANDLE, columnA2Symbol, COLUMN_A2_HANDLE), leftContraint);
TableScanNode right = p.tableScan(TABLE_B_HANDLE, ImmutableList.of(columnB1Symbol), ImmutableMap.of(columnB1Symbol, COLUMN_B1_HANDLE), rightConstraint);
return p.join(INNER, left, right, new JoinNode.EquiJoinClause(columnA1Symbol, columnB1Symbol));
}).withSession(MOCK_SESSION).matches(anyTree());
}).isInstanceOf(IllegalStateException.class).hasMessageContaining("Column handle mappings do not match old column handles");
}
}
use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.
the class TestRemoveRedundantPredicateAboveTableScan method skipNotFullyExtractedConjunct.
@Test
public void skipNotFullyExtractedConjunct() {
ColumnHandle textColumnHandle = new TpchColumnHandle("name", VARCHAR);
ColumnHandle nationKeyColumnHandle = new TpchColumnHandle("nationkey", BIGINT);
tester().assertThat(removeRedundantPredicateAboveTableScan).on(p -> p.filter(expression("name LIKE 'LARGE PLATED %' AND nationkey = BIGINT '44'"), p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("name", VARCHAR), p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("name", VARCHAR), textColumnHandle, p.symbol("nationkey", BIGINT), nationKeyColumnHandle), TupleDomain.fromFixedValues(ImmutableMap.of(textColumnHandle, NullableValue.of(VARCHAR, Slices.utf8Slice("value")), nationKeyColumnHandle, NullableValue.of(BIGINT, (long) 44)))))).matches(filter(expression("name LIKE 'LARGE PLATED %'"), constrainedTableScanWithTableLayout("nation", ImmutableMap.of("nationkey", Domain.singleValue(BIGINT, 44L), "name", Domain.singleValue(VARCHAR, Slices.utf8Slice("value"))), ImmutableMap.of("nationkey", "nationkey", "name", "name"))));
}
use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.
the class TestRemoveRedundantPredicateAboveTableScan method doesNotFireOnNonDeterministicPredicate.
@Test
public void doesNotFireOnNonDeterministicPredicate() {
ColumnHandle columnHandle = new TpchColumnHandle("nationkey", BIGINT);
tester().assertThat(removeRedundantPredicateAboveTableScan).on(p -> p.filter(new ComparisonExpression(EQUAL, FunctionCallBuilder.resolve(tester().getSession(), tester().getMetadata()).setName(QualifiedName.of("rand")).build(), new GenericLiteral("BIGINT", "42")), p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), columnHandle), TupleDomain.all()))).doesNotFire();
}
use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.
the class TestRemoveRedundantPredicateAboveTableScan method doesNotFireOnNoTableScanPredicate.
@Test
public void doesNotFireOnNoTableScanPredicate() {
ColumnHandle columnHandle = new TpchColumnHandle("nationkey", BIGINT);
tester().assertThat(removeRedundantPredicateAboveTableScan).on(p -> p.filter(expression("(nationkey > 3 OR nationkey > 0) AND (nationkey > 3 OR nationkey < 1)"), p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), columnHandle), TupleDomain.all()))).doesNotFire();
}
use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.
the class TestRemoveRedundantPredicateAboveTableScan method doesNotConsumeRemainingPredicateIfNewDomainIsWider.
@Test
public void doesNotConsumeRemainingPredicateIfNewDomainIsWider() {
ColumnHandle columnHandle = new TpchColumnHandle("nationkey", BIGINT);
tester().assertThat(removeRedundantPredicateAboveTableScan).on(p -> p.filter(new LogicalExpression(AND, ImmutableList.of(new ComparisonExpression(EQUAL, FunctionCallBuilder.resolve(tester().getSession(), tester().getMetadata()).setName(QualifiedName.of("rand")).build(), new GenericLiteral("BIGINT", "42")), new ComparisonExpression(EQUAL, new ArithmeticBinaryExpression(MODULUS, new SymbolReference("nationkey"), new GenericLiteral("BIGINT", "17")), new GenericLiteral("BIGINT", "44")), LogicalExpression.or(new ComparisonExpression(EQUAL, new SymbolReference("nationkey"), new GenericLiteral("BIGINT", "44")), new ComparisonExpression(EQUAL, new SymbolReference("nationkey"), new GenericLiteral("BIGINT", "45"))))), p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), columnHandle), TupleDomain.fromFixedValues(ImmutableMap.of(columnHandle, NullableValue.of(BIGINT, (long) 44)))))).matches(filter(LogicalExpression.and(new ComparisonExpression(EQUAL, FunctionCallBuilder.resolve(tester().getSession(), tester().getMetadata()).setName(QualifiedName.of("rand")).build(), new GenericLiteral("BIGINT", "42")), new ComparisonExpression(EQUAL, new ArithmeticBinaryExpression(MODULUS, new SymbolReference("nationkey"), new GenericLiteral("BIGINT", "17")), new GenericLiteral("BIGINT", "44"))), constrainedTableScanWithTableLayout("nation", ImmutableMap.of("nationkey", singleValue(BIGINT, (long) 44)), ImmutableMap.of("nationkey", "nationkey"))));
}
Aggregations