Search in sources :

Example 1 with InformationSchemaMetadata

use of io.prestosql.connector.informationschema.InformationSchemaMetadata in project hetu-core by openlookeng.

the class TestInformationSchemaMetadata method testInformationSchemaPredicatePushdownWithConstraintPredicate.

@Test
public void testInformationSchemaPredicatePushdownWithConstraintPredicate() {
    TransactionId transactionId = transactionManager.beginTransaction(false);
    Constraint constraint = new Constraint(TupleDomain.all(), // test_schema has a table named "another_table" and we filter that out in this predicate
    bindings -> {
        NullableValue catalog = bindings.get(new InformationSchemaColumnHandle("table_catalog"));
        NullableValue schema = bindings.get(new InformationSchemaColumnHandle("table_schema"));
        NullableValue table = bindings.get(new InformationSchemaColumnHandle("table_name"));
        boolean isValid = true;
        if (catalog != null) {
            isValid = ((Slice) catalog.getValue()).toStringUtf8().equals("test_catalog");
        }
        if (schema != null) {
            isValid &= ((Slice) schema.getValue()).toStringUtf8().equals("test_schema");
        }
        if (table != null) {
            isValid &= ((Slice) table.getValue()).toStringUtf8().equals("test_view");
        }
        return isValid;
    });
    ConnectorSession session = createNewSession(transactionId);
    ConnectorMetadata connectorMetadata = new InformationSchemaMetadata("test_catalog", this.metadata);
    InformationSchemaTableHandle tableHandle = (InformationSchemaTableHandle) connectorMetadata.getTableHandle(session, new SchemaTableName("information_schema", "views"));
    tableHandle = connectorMetadata.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", "test_view")));
}
Also used : InformationSchemaTableHandle(io.prestosql.connector.informationschema.InformationSchemaTableHandle) Constraint(io.prestosql.spi.connector.Constraint) Slice(io.airlift.slice.Slice) InformationSchemaColumnHandle(io.prestosql.connector.informationschema.InformationSchemaColumnHandle) NullableValue(io.prestosql.spi.predicate.NullableValue) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) InformationSchemaMetadata(io.prestosql.connector.informationschema.InformationSchemaMetadata) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) TransactionId(io.prestosql.transaction.TransactionId) Test(org.testng.annotations.Test)

Example 2 with InformationSchemaMetadata

use of io.prestosql.connector.informationschema.InformationSchemaMetadata in project hetu-core by openlookeng.

the class TestInformationSchemaMetadata method testInformationSchemaPredicatePushdown.

/**
 * Tests information schema predicate pushdown when both schema and table name are specified.
 */
@Test
public void testInformationSchemaPredicatePushdown() {
    TransactionId transactionId = transactionManager.beginTransaction(false);
    ImmutableMap.Builder<ColumnHandle, Domain> domains = new ImmutableMap.Builder<>();
    domains.put(new InformationSchemaColumnHandle("table_schema"), Domain.singleValue(VARCHAR, Slices.utf8Slice("test_schema")));
    domains.put(new InformationSchemaColumnHandle("table_name"), Domain.singleValue(VARCHAR, Slices.utf8Slice("test_view")));
    Constraint constraint = new Constraint(TupleDomain.withColumnDomains(domains.build()));
    ConnectorSession session = createNewSession(transactionId);
    ConnectorMetadata connectorMetadata = new InformationSchemaMetadata("test_catalog", this.metadata);
    InformationSchemaTableHandle tableHandle = (InformationSchemaTableHandle) connectorMetadata.getTableHandle(session, new SchemaTableName("information_schema", "views"));
    tableHandle = connectorMetadata.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", "test_view")));
}
Also used : InformationSchemaColumnHandle(io.prestosql.connector.informationschema.InformationSchemaColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Constraint(io.prestosql.spi.connector.Constraint) TestingSession.testSessionBuilder(io.prestosql.testing.TestingSession.testSessionBuilder) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) TransactionId(io.prestosql.transaction.TransactionId) InformationSchemaTableHandle(io.prestosql.connector.informationschema.InformationSchemaTableHandle) InformationSchemaColumnHandle(io.prestosql.connector.informationschema.InformationSchemaColumnHandle) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) InformationSchemaMetadata(io.prestosql.connector.informationschema.InformationSchemaMetadata) TupleDomain(io.prestosql.spi.predicate.TupleDomain) Domain(io.prestosql.spi.predicate.Domain) Test(org.testng.annotations.Test)

Aggregations

InformationSchemaColumnHandle (io.prestosql.connector.informationschema.InformationSchemaColumnHandle)2 InformationSchemaMetadata (io.prestosql.connector.informationschema.InformationSchemaMetadata)2 InformationSchemaTableHandle (io.prestosql.connector.informationschema.InformationSchemaTableHandle)2 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)2 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)2 Constraint (io.prestosql.spi.connector.Constraint)2 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)2 TransactionId (io.prestosql.transaction.TransactionId)2 Test (org.testng.annotations.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Slice (io.airlift.slice.Slice)1 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)1 Domain (io.prestosql.spi.predicate.Domain)1 NullableValue (io.prestosql.spi.predicate.NullableValue)1 TupleDomain (io.prestosql.spi.predicate.TupleDomain)1 TestingSession.testSessionBuilder (io.prestosql.testing.TestingSession.testSessionBuilder)1