Search in sources :

Example 11 with Constraint

use of io.trino.spi.connector.Constraint in project trino by trinodb.

the class TestInformationSchemaMetadata method testInformationSchemaPredicatePushdownWithoutTablePredicate.

@Test
public void testInformationSchemaPredicatePushdownWithoutTablePredicate() {
    TransactionId transactionId = transactionManager.beginTransaction(false);
    // predicate without table name predicates should not cause table level prefixes to be evaluated
    ImmutableMap.Builder<ColumnHandle, Domain> domains = ImmutableMap.builder();
    domains.put(new InformationSchemaColumnHandle("table_schema"), Domain.singleValue(VARCHAR, Slices.utf8Slice("test_schema")));
    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);
    assertEquals(tableHandle.getPrefixes(), ImmutableSet.of(new QualifiedTablePrefix("test_catalog", "test_schema")));
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) InformationSchemaColumnHandle(io.trino.connector.informationschema.InformationSchemaColumnHandle) Constraint(io.trino.spi.connector.Constraint) SchemaTableName(io.trino.spi.connector.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) TransactionId(io.trino.transaction.TransactionId) InformationSchemaTableHandle(io.trino.connector.informationschema.InformationSchemaTableHandle) InformationSchemaColumnHandle(io.trino.connector.informationschema.InformationSchemaColumnHandle) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) InformationSchemaMetadata(io.trino.connector.informationschema.InformationSchemaMetadata) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) Test(org.testng.annotations.Test)

Example 12 with Constraint

use of io.trino.spi.connector.Constraint 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")));
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) InformationSchemaColumnHandle(io.trino.connector.informationschema.InformationSchemaColumnHandle) Constraint(io.trino.spi.connector.Constraint) SchemaTableName(io.trino.spi.connector.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) TransactionId(io.trino.transaction.TransactionId) InformationSchemaTableHandle(io.trino.connector.informationschema.InformationSchemaTableHandle) InformationSchemaColumnHandle(io.trino.connector.informationschema.InformationSchemaColumnHandle) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) InformationSchemaMetadata(io.trino.connector.informationschema.InformationSchemaMetadata) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) Test(org.testng.annotations.Test)

Example 13 with Constraint

use of io.trino.spi.connector.Constraint 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\"");
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) Constraint(io.trino.spi.connector.Constraint) ConnectorSession(io.trino.spi.connector.ConnectorSession) TestingConnectorSession(io.trino.testing.TestingConnectorSession) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 14 with Constraint

use of io.trino.spi.connector.Constraint 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\"");
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) Constraint(io.trino.spi.connector.Constraint) ConnectorSession(io.trino.spi.connector.ConnectorSession) TestingConnectorSession(io.trino.testing.TestingConnectorSession) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 15 with Constraint

use of io.trino.spi.connector.Constraint 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\"))");
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) Constraint(io.trino.spi.connector.Constraint) ConnectorSession(io.trino.spi.connector.ConnectorSession) TestingConnectorSession(io.trino.testing.TestingConnectorSession) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Aggregations

Constraint (io.trino.spi.connector.Constraint)41 ColumnHandle (io.trino.spi.connector.ColumnHandle)32 SchemaTableName (io.trino.spi.connector.SchemaTableName)28 TupleDomain (io.trino.spi.predicate.TupleDomain)27 ConnectorSession (io.trino.spi.connector.ConnectorSession)26 Domain (io.trino.spi.predicate.Domain)23 Test (org.testng.annotations.Test)23 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)20 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)18 ConstraintApplicationResult (io.trino.spi.connector.ConstraintApplicationResult)18 Map (java.util.Map)18 Objects.requireNonNull (java.util.Objects.requireNonNull)18 Optional (java.util.Optional)18 ImmutableMap (com.google.common.collect.ImmutableMap)17 List (java.util.List)17 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)16 ImmutableList (com.google.common.collect.ImmutableList)15 Set (java.util.Set)15 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)14 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)13