use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.
the class TestDefaultJdbcMetadata method testCombineFiltersWithAggregationPushdown.
@Test
public void testCombineFiltersWithAggregationPushdown() {
ConnectorSession session = TestingConnectorSession.builder().setPropertyMetadata(new JdbcMetadataSessionProperties(new JdbcMetadataConfig().setAggregationPushdownEnabled(true), Optional.empty()).getSessionProperties()).build();
ColumnHandle groupByColumn = metadata.getColumnHandles(session, tableHandle).get("text");
ConnectorTableHandle baseTableHandle = metadata.getTableHandle(session, new SchemaTableName("example", "numbers"));
Domain firstDomain = Domain.multipleValues(VARCHAR, ImmutableList.of(utf8Slice("one"), utf8Slice("two")));
JdbcTableHandle filterResult = applyFilter(session, baseTableHandle, new Constraint(TupleDomain.withColumnDomains(ImmutableMap.of(groupByColumn, firstDomain))));
ConnectorTableHandle aggregatedTable = applyCountAggregation(session, filterResult, ImmutableList.of(ImmutableList.of(groupByColumn)));
Domain secondDomain = Domain.multipleValues(VARCHAR, ImmutableList.of(utf8Slice("one"), utf8Slice("three")));
JdbcTableHandle tableHandleWithFilter = applyFilter(session, aggregatedTable, new Constraint(TupleDomain.withColumnDomains(ImmutableMap.of(groupByColumn, secondDomain))));
assertEquals(tableHandleWithFilter.getConstraint().getDomains(), // as firstDomain has been converted into a PreparedQuery
Optional.of(ImmutableMap.of(groupByColumn, secondDomain)));
assertEquals(((JdbcQueryRelationHandle) tableHandleWithFilter.getRelationHandle()).getPreparedQuery().getQuery(), "SELECT \"TEXT\", count(*) AS \"_pfgnrtd_0\" " + "FROM \"" + database.getDatabaseName() + "\".\"EXAMPLE\".\"NUMBERS\" " + "WHERE \"TEXT\" IN (?,?) " + "GROUP BY \"TEXT\"");
}
use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.
the class TestDefaultJdbcMetadata method testNonGroupKeyPredicatePushdown.
@Test
public void testNonGroupKeyPredicatePushdown() {
ConnectorSession session = TestingConnectorSession.builder().setPropertyMetadata(new JdbcMetadataSessionProperties(new JdbcMetadataConfig().setAggregationPushdownEnabled(true), Optional.empty()).getSessionProperties()).build();
Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
ColumnHandle groupByColumn = columnHandles.get("text");
ColumnHandle nonGroupByColumn = columnHandles.get("value");
ConnectorTableHandle baseTableHandle = metadata.getTableHandle(session, new SchemaTableName("example", "numbers"));
ConnectorTableHandle aggregatedTable = applyCountAggregation(session, baseTableHandle, ImmutableList.of(ImmutableList.of(groupByColumn)));
Domain domain = Domain.singleValue(BIGINT, 123L);
JdbcTableHandle tableHandleWithFilter = applyFilter(session, aggregatedTable, new Constraint(TupleDomain.withColumnDomains(ImmutableMap.of(nonGroupByColumn, domain))));
assertEquals(tableHandleWithFilter.getConstraint().getDomains(), Optional.of(ImmutableMap.of(nonGroupByColumn, domain)));
assertEquals(((JdbcQueryRelationHandle) tableHandleWithFilter.getRelationHandle()).getPreparedQuery().getQuery(), "SELECT \"TEXT\", count(*) AS \"_pfgnrtd_0\" " + "FROM \"" + database.getDatabaseName() + "\".\"EXAMPLE\".\"NUMBERS\" " + "GROUP BY \"TEXT\"");
}
use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.
the class TestDefaultJdbcMetadata method tesMultiGroupKeyPredicatePushdown.
@Test
public void tesMultiGroupKeyPredicatePushdown() {
ConnectorSession session = TestingConnectorSession.builder().setPropertyMetadata(new JdbcMetadataSessionProperties(new JdbcMetadataConfig().setAggregationPushdownEnabled(true), Optional.empty()).getSessionProperties()).build();
Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
ColumnHandle textColumn = columnHandles.get("text");
ColumnHandle valueColumn = columnHandles.get("value");
ConnectorTableHandle baseTableHandle = metadata.getTableHandle(session, new SchemaTableName("example", "numbers"));
ConnectorTableHandle aggregatedTable = applyCountAggregation(session, baseTableHandle, ImmutableList.of(ImmutableList.of(textColumn, valueColumn), ImmutableList.of(textColumn)));
Domain domain = Domain.singleValue(BIGINT, 123L);
JdbcTableHandle tableHandleWithFilter = applyFilter(session, aggregatedTable, new Constraint(TupleDomain.withColumnDomains(ImmutableMap.of(valueColumn, domain))));
assertEquals(tableHandleWithFilter.getConstraint().getDomains(), Optional.of(ImmutableMap.of(valueColumn, domain)));
assertEquals(((JdbcQueryRelationHandle) tableHandleWithFilter.getRelationHandle()).getPreparedQuery().getQuery(), "SELECT \"TEXT\", \"VALUE\", count(*) AS \"_pfgnrtd_0\" " + "FROM \"" + database.getDatabaseName() + "\".\"EXAMPLE\".\"NUMBERS\" " + "GROUP BY GROUPING SETS ((\"TEXT\", \"VALUE\"), (\"TEXT\"))");
}
use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.
the class TestDefaultJdbcQueryBuilder method testBuildSqlWithTimestamp.
@Test
public void testBuildSqlWithTimestamp() throws SQLException {
TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(columns.get(6), Domain.create(SortedRangeSet.copyOf(TIMESTAMP_MILLIS, ImmutableList.of(Range.equal(TIMESTAMP_MILLIS, toPrestoTimestamp(2016, 6, 3, 0, 23, 37)), Range.equal(TIMESTAMP_MILLIS, toPrestoTimestamp(2016, 10, 19, 16, 23, 37)), Range.range(TIMESTAMP_MILLIS, toPrestoTimestamp(2016, 6, 7, 8, 23, 37), false, toPrestoTimestamp(2016, 6, 9, 12, 23, 37), true))), false)));
Connection connection = database.getConnection();
PreparedQuery preparedQuery = queryBuilder.prepareSelectQuery(jdbcClient, SESSION, connection, TEST_TABLE, Optional.empty(), columns, Map.of(), tupleDomain, Optional.empty());
try (PreparedStatement preparedStatement = queryBuilder.prepareStatement(jdbcClient, SESSION, connection, preparedQuery)) {
assertThat(preparedQuery.getQuery()).isEqualTo("" + "SELECT \"col_0\", \"col_1\", \"col_2\", \"col_3\", \"col_4\", \"col_5\", " + "\"col_6\", \"col_7\", \"col_8\", \"col_9\", \"col_10\", \"col_11\" " + "FROM \"test_table\" " + "WHERE ((\"col_6\" > ? AND \"col_6\" <= ?) OR \"col_6\" IN (?,?))");
ImmutableSet.Builder<Timestamp> builder = ImmutableSet.builder();
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
builder.add((Timestamp) resultSet.getObject("col_6"));
}
}
assertEquals(builder.build(), ImmutableSet.of(toTimestamp(2016, 6, 3, 0, 23, 37), toTimestamp(2016, 6, 8, 10, 23, 37), toTimestamp(2016, 6, 9, 12, 23, 37), toTimestamp(2016, 10, 19, 16, 23, 37)));
assertContains(preparedStatement.toString(), "\"col_6\" > ?");
assertContains(preparedStatement.toString(), "\"col_6\" <= ?");
assertContains(preparedStatement.toString(), "\"col_6\" IN (?,?)");
}
}
use of io.trino.spi.connector.ColumnHandle in project trino by trinodb.
the class TestDefaultJdbcQueryBuilder method testBuildSqlWithFloat.
@Test
public void testBuildSqlWithFloat() throws SQLException {
TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(columns.get(10), Domain.create(SortedRangeSet.copyOf(REAL, ImmutableList.of(Range.equal(REAL, (long) floatToRawIntBits(100.0f + 0)), Range.equal(REAL, (long) floatToRawIntBits(100.008f + 0)), Range.equal(REAL, (long) floatToRawIntBits(100.0f + 14)))), false)));
Connection connection = database.getConnection();
PreparedQuery preparedQuery = queryBuilder.prepareSelectQuery(jdbcClient, SESSION, connection, TEST_TABLE, Optional.empty(), columns, Map.of(), tupleDomain, Optional.empty());
try (PreparedStatement preparedStatement = queryBuilder.prepareStatement(jdbcClient, SESSION, connection, preparedQuery)) {
assertThat(preparedQuery.getQuery()).isEqualTo("" + "SELECT \"col_0\", \"col_1\", \"col_2\", \"col_3\", \"col_4\", \"col_5\", " + "\"col_6\", \"col_7\", \"col_8\", \"col_9\", \"col_10\", \"col_11\" " + "FROM \"test_table\" " + "WHERE \"col_10\" IN (?,?,?)");
ImmutableSet.Builder<Long> longBuilder = ImmutableSet.builder();
ImmutableSet.Builder<Float> floatBuilder = ImmutableSet.builder();
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
longBuilder.add((Long) resultSet.getObject("col_0"));
floatBuilder.add((Float) resultSet.getObject("col_10"));
}
}
assertEquals(longBuilder.build(), ImmutableSet.of(0L, 14L));
assertEquals(floatBuilder.build(), ImmutableSet.of(100.0f, 114.0f));
}
}
Aggregations