Search in sources :

Example 1 with InformationSchemaTableHandle

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

the class TestInformationSchemaTableHandle method testInformationSchemaSerialize.

@Test
public void testInformationSchemaSerialize() throws Exception {
    InformationSchemaTableHandle informationSchemaTableHandle = new InformationSchemaTableHandle("information_schema_catalog", "information_schema_schema", "information_schema_table", ImmutableSet.of(new QualifiedTablePrefix("abc", "xyz")));
    assertTrue(objectMapper.canSerialize(InformationSchemaTableHandle.class));
    String json = objectMapper.writeValueAsString(informationSchemaTableHandle);
    testJsonEquals(json, SCHEMA_AS_MAP);
}
Also used : InformationSchemaTableHandle(io.prestosql.connector.informationschema.InformationSchemaTableHandle) Test(org.testng.annotations.Test)

Example 2 with InformationSchemaTableHandle

use of io.prestosql.connector.informationschema.InformationSchemaTableHandle 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 3 with InformationSchemaTableHandle

use of io.prestosql.connector.informationschema.InformationSchemaTableHandle 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)

Example 4 with InformationSchemaTableHandle

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

the class TestInformationSchemaTableHandle method testInformationSchemaDeserialize.

@Test
public void testInformationSchemaDeserialize() throws Exception {
    String json = objectMapper.writeValueAsString(SCHEMA_AS_MAP);
    ConnectorTableHandle tableHandle = objectMapper.readValue(json, ConnectorTableHandle.class);
    assertEquals(tableHandle.getClass(), InformationSchemaTableHandle.class);
    InformationSchemaTableHandle informationSchemaHandle = (InformationSchemaTableHandle) tableHandle;
    assertEquals(informationSchemaHandle.getCatalogName(), "information_schema_catalog");
    assertEquals(informationSchemaHandle.getSchemaName(), "information_schema_schema");
    assertEquals(informationSchemaHandle.getTableName(), "information_schema_table");
}
Also used : InformationSchemaTableHandle(io.prestosql.connector.informationschema.InformationSchemaTableHandle) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Aggregations

InformationSchemaTableHandle (io.prestosql.connector.informationschema.InformationSchemaTableHandle)4 Test (org.testng.annotations.Test)4 InformationSchemaColumnHandle (io.prestosql.connector.informationschema.InformationSchemaColumnHandle)2 InformationSchemaMetadata (io.prestosql.connector.informationschema.InformationSchemaMetadata)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 ImmutableMap (com.google.common.collect.ImmutableMap)1 Slice (io.airlift.slice.Slice)1 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)1 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)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