use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.
the class TestInformationSchemaMetadata method testInformationSchemaPredicatePushdownWithoutSchemaPredicate.
@Test
public void testInformationSchemaPredicatePushdownWithoutSchemaPredicate() {
TransactionId transactionId = transactionManager.beginTransaction(false);
// predicate without schema predicates should cause schemas to be enumerated when table predicates are present
ImmutableMap.Builder<ColumnHandle, Domain> domains = ImmutableMap.builder();
domains.put(new InformationSchemaColumnHandle("table_name"), Domain.singleValue(VARCHAR, Slices.utf8Slice("test_view")));
Constraint constraint = new Constraint(TupleDomain.withColumnDomains(domains.buildOrThrow()));
ConnectorSession session = createNewSession(transactionId);
ConnectorMetadata metadata = new InformationSchemaMetadata("test_catalog", this.metadata);
InformationSchemaTableHandle tableHandle = (InformationSchemaTableHandle) metadata.getTableHandle(session, new SchemaTableName("information_schema", "views"));
tableHandle = metadata.applyFilter(session, tableHandle, constraint).map(ConstraintApplicationResult::getHandle).map(InformationSchemaTableHandle.class::cast).orElseThrow(AssertionError::new);
// filter blindly applies filter to all visible schemas, so information_schema must be included
assertEquals(tableHandle.getPrefixes(), ImmutableSet.of(new QualifiedTablePrefix("test_catalog", "test_schema", "test_view"), new QualifiedTablePrefix("test_catalog", "information_schema", "test_view")));
}
use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.
the class TestDefaultJdbcMetadata method testAggregationPushdownForTableHandle.
@Test
public void testAggregationPushdownForTableHandle() {
ConnectorSession session = TestingConnectorSession.builder().setPropertyMetadata(new JdbcMetadataSessionProperties(new JdbcMetadataConfig().setAggregationPushdownEnabled(true), Optional.empty()).getSessionProperties()).build();
ColumnHandle groupByColumn = metadata.getColumnHandles(session, tableHandle).get("text");
Function<ConnectorTableHandle, Optional<AggregationApplicationResult<ConnectorTableHandle>>> applyAggregation = handle -> metadata.applyAggregation(session, handle, ImmutableList.of(new AggregateFunction("count", BIGINT, List.of(), List.of(), false, Optional.empty())), ImmutableMap.of(), ImmutableList.of(ImmutableList.of(groupByColumn)));
ConnectorTableHandle baseTableHandle = metadata.getTableHandle(session, new SchemaTableName("example", "numbers"));
Optional<AggregationApplicationResult<ConnectorTableHandle>> aggregationResult = applyAggregation.apply(baseTableHandle);
assertThat(aggregationResult).isPresent();
SchemaTableName noAggregationPushdownTable = new SchemaTableName("example", "no_aggregation_pushdown");
metadata.createTable(SESSION, new ConnectorTableMetadata(noAggregationPushdownTable, ImmutableList.of(new ColumnMetadata("text", VARCHAR))), false);
ConnectorTableHandle noAggregationPushdownTableHandle = metadata.getTableHandle(session, noAggregationPushdownTable);
aggregationResult = applyAggregation.apply(noAggregationPushdownTableHandle);
assertThat(aggregationResult).isEmpty();
}
use of io.trino.spi.connector.ConnectorSession 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.ConnectorSession 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.ConnectorSession 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\"))");
}
Aggregations