Search in sources :

Example 6 with SchemaTablePrefix

use of io.prestosql.spi.connector.SchemaTablePrefix in project boostkit-bigdata by kunpengcompute.

the class AbstractTestHive method testListUnknownSchema.

@Test
public void testListUnknownSchema() {
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        ConnectorSession session = newSession();
        assertNull(metadata.getTableHandle(session, new SchemaTableName(INVALID_DATABASE, INVALID_TABLE)));
        assertEquals(metadata.listTables(session, Optional.of(INVALID_DATABASE)), ImmutableList.of());
        assertEquals(metadata.listTableColumns(session, new SchemaTablePrefix(INVALID_DATABASE, INVALID_TABLE)), ImmutableMap.of());
        assertEquals(metadata.listViews(session, Optional.of(INVALID_DATABASE)), ImmutableList.of());
        assertEquals(metadata.getViews(session, Optional.of(INVALID_DATABASE)), ImmutableMap.of());
        assertEquals(metadata.getView(session, new SchemaTableName(INVALID_DATABASE, INVALID_TABLE)), Optional.empty());
    }
}
Also used : SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) TestingConnectorSession(io.prestosql.testing.TestingConnectorSession) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 7 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 8 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)

Example 9 with SchemaTablePrefix

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

the class MetadataManager method listTableColumns.

@Override
public Map<QualifiedObjectName, List<ColumnMetadata>> listTableColumns(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Map<QualifiedObjectName, List<ColumnMetadata>> tableColumns = new HashMap<>();
    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);
            for (Entry<SchemaTableName, List<ColumnMetadata>> entry : metadata.listTableColumns(connectorSession, tablePrefix).entrySet()) {
                QualifiedObjectName tableName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
                tableColumns.put(tableName, entry.getValue());
            }
            // if table and view names overlap, the view wins
            for (Entry<QualifiedObjectName, ConnectorViewDefinition> entry : getViews(session, prefix).entrySet()) {
                ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
                for (ViewColumn column : entry.getValue().getColumns()) {
                    try {
                        columns.add(new ColumnMetadata(column.getName(), getType(column.getType())));
                    } catch (TypeNotFoundException e) {
                        throw new PrestoException(INVALID_VIEW, format("Unknown type '%s' for column '%s' in view: %s", column.getType(), column.getName(), entry.getKey()));
                    }
                }
                tableColumns.put(entry.getKey(), columns.build());
            }
        }
    }
    return ImmutableMap.copyOf(tableColumns);
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) ViewColumn(io.prestosql.spi.connector.ConnectorViewDefinition.ViewColumn) SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) PrestoException(io.prestosql.spi.PrestoException) 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) TypeNotFoundException(io.prestosql.spi.type.TypeNotFoundException) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) CatalogName(io.prestosql.spi.connector.CatalogName) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata)

Example 10 with SchemaTablePrefix

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

the class AbstractTestHive method testGetAllTableColumnsInSchema.

@Test
public void testGetAllTableColumnsInSchema() {
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        Map<SchemaTableName, List<ColumnMetadata>> allColumns = metadata.listTableColumns(newSession(), new SchemaTablePrefix(database));
        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)

Aggregations

SchemaTablePrefix (io.prestosql.spi.connector.SchemaTablePrefix)15 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)13 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)12 Test (org.testng.annotations.Test)12 List (java.util.List)9 ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)7 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)7 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)6 Collectors.toList (java.util.stream.Collectors.toList)6 TestingConnectorSession (io.prestosql.testing.TestingConnectorSession)4 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)3 ViewColumn (io.prestosql.spi.connector.ConnectorViewDefinition.ViewColumn)3 MetadataUtil.convertFromSchemaTableName (io.prestosql.metadata.MetadataUtil.convertFromSchemaTableName)2 MetadataUtil.toSchemaTableName (io.prestosql.metadata.MetadataUtil.toSchemaTableName)2 Column (io.prestosql.plugin.hive.metastore.Column)2 PrincipalPrivileges (io.prestosql.plugin.hive.metastore.PrincipalPrivileges)2 SemiTransactionalHiveMetastore (io.prestosql.plugin.hive.metastore.SemiTransactionalHiveMetastore)2 SortingColumn (io.prestosql.plugin.hive.metastore.SortingColumn)2 Table (io.prestosql.plugin.hive.metastore.Table)2