Search in sources :

Example 1 with SchemaTablePrefix

use of io.prestosql.spi.connector.SchemaTablePrefix in project hetu-core by openlookeng.

the class MetadataManager method getViews.

@Override
public Map<QualifiedObjectName, ConnectorViewDefinition> getViews(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Map<QualifiedObjectName, ConnectorViewDefinition> views = new LinkedHashMap<>();
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix();
        for (CatalogName catalogName : catalogMetadata.listConnectorIds()) {
            ConnectorMetadata metadata = catalogMetadata.getMetadataFor(catalogName);
            ConnectorSession connectorSession = session.toConnectorSession(catalogName);
            Map<SchemaTableName, ConnectorViewDefinition> viewMap;
            if (tablePrefix.getTable().isPresent()) {
                viewMap = metadata.getView(connectorSession, tablePrefix.toSchemaTableName()).map(view -> ImmutableMap.of(tablePrefix.toSchemaTableName(), view)).orElse(ImmutableMap.of());
            } else {
                viewMap = metadata.getViews(connectorSession, tablePrefix.getSchema());
            }
            for (Entry<SchemaTableName, ConnectorViewDefinition> entry : viewMap.entrySet()) {
                QualifiedObjectName viewName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
                views.put(viewName, entry.getValue());
            }
        }
    }
    return ImmutableMap.copyOf(views);
}
Also used : SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) MetadataUtil.toSchemaTableName(io.prestosql.metadata.MetadataUtil.toSchemaTableName) MetadataUtil.convertFromSchemaTableName(io.prestosql.metadata.MetadataUtil.convertFromSchemaTableName) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) LinkedHashMap(java.util.LinkedHashMap) CatalogName(io.prestosql.spi.connector.CatalogName) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata)

Example 2 with SchemaTablePrefix

use of io.prestosql.spi.connector.SchemaTablePrefix in project hetu-core by openlookeng.

the class AbstractTestHive method testGetAllTableColumns.

@Test
public void testGetAllTableColumns() {
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        Map<SchemaTableName, List<ColumnMetadata>> allColumns = metadata.listTableColumns(newSession(), new SchemaTablePrefix());
        assertTrue(allColumns.containsKey(tablePartitionFormat));
        assertTrue(allColumns.containsKey(tableUnpartitioned));
    }
}
Also used : SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 3 with SchemaTablePrefix

use of io.prestosql.spi.connector.SchemaTablePrefix in project hetu-core by openlookeng.

the class AbstractTestHive method testHiveViewsHaveNoColumns.

@Test
public void testHiveViewsHaveNoColumns() {
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        assertEquals(metadata.listTableColumns(newSession(), new SchemaTablePrefix(view.getSchemaName(), view.getTableName())), ImmutableMap.of());
    }
}
Also used : SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) Test(org.testng.annotations.Test)

Example 4 with SchemaTablePrefix

use of io.prestosql.spi.connector.SchemaTablePrefix in project hetu-core by openlookeng.

the class TestHBase method testListTableColumns.

/**
 * testListTableColumns
 */
@Test
public void testListTableColumns() {
    Map<SchemaTableName, List<ColumnMetadata>> tables = hcm.listTableColumns(session, new SchemaTablePrefix("hbase", "test_table"));
    assertEquals(5, tables.get(new SchemaTableName("hbase", "test_table")).size());
}
Also used : SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) List(java.util.List) ArrayList(java.util.ArrayList) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 5 with SchemaTablePrefix

use of io.prestosql.spi.connector.SchemaTablePrefix in project hetu-core by openlookeng.

the class TestCachingJdbcMetadata method testListTableColumns.

@Test
public void testListTableColumns() throws SQLException, InterruptedException {
    // add cachingtable
    database.getConnection().createStatement().execute("CREATE SCHEMA cachingschema");
    database.getConnection().createStatement().execute("CREATE TABLE cachingschema.cachingtable(id varchar primary key)");
    // should only have one column
    SchemaTablePrefix tablePrefix = new SchemaTablePrefix("cachingschema", "cachingtable");
    assertEquals(metadata.listTableColumns(session, tablePrefix), ImmutableMap.of(cachingSchemaTableName, ImmutableList.of(new ColumnMetadata("id", VARCHAR, false, null, null, false, emptyMap()))));
    // add a new column
    database.getConnection().createStatement().execute("ALTER TABLE cachingschema.cachingtable ADD COLUMN value VARCHAR(50)");
    // should still only have one column bc it is cached
    assertEquals(metadata.listTableColumns(session, tablePrefix), ImmutableMap.of(cachingSchemaTableName, ImmutableList.of(new ColumnMetadata("id", VARCHAR, false, null, null, false, emptyMap()))));
    // wait for cache to expire
    Thread.sleep(CACHE_TTL + 50);
    // should now see the new column
    assertEquals(metadata.listTableColumns(session, tablePrefix), ImmutableMap.of(cachingSchemaTableName, ImmutableList.of(new ColumnMetadata("id", VARCHAR, false, null, null, false, emptyMap()), new ColumnMetadata("value", createVarcharType(50)))));
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) Test(org.testng.annotations.Test)

Aggregations

SchemaTablePrefix (io.prestosql.spi.connector.SchemaTablePrefix)10 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)8 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)8 Test (org.testng.annotations.Test)7 List (java.util.List)6 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)3 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)3 Collectors.toList (java.util.stream.Collectors.toList)3 MetadataUtil.convertFromSchemaTableName (io.prestosql.metadata.MetadataUtil.convertFromSchemaTableName)2 MetadataUtil.toSchemaTableName (io.prestosql.metadata.MetadataUtil.toSchemaTableName)2 PrestoException (io.prestosql.spi.PrestoException)2 CatalogName (io.prestosql.spi.connector.CatalogName)2 ConnectorViewDefinition (io.prestosql.spi.connector.ConnectorViewDefinition)2 ViewColumn (io.prestosql.spi.connector.ConnectorViewDefinition.ViewColumn)2 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)2 TestingConnectorSession (io.prestosql.testing.TestingConnectorSession)2 ArrayList (java.util.ArrayList)2