Search in sources :

Example 11 with SchemaTablePrefix

use of com.facebook.presto.spi.SchemaTablePrefix in project presto by prestodb.

the class SystemTablesMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    if (prefix.getTableName() != null) {
        // if table is concrete we just use tables.getSystemTable to support tables which are not listable
        SchemaTableName tableName = prefix.toSchemaTableName();
        return tables.getSystemTable(session, tableName).map(systemTable -> singletonMap(tableName, systemTable.getTableMetadata().getColumns())).orElseGet(ImmutableMap::of);
    }
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> builder = ImmutableMap.builder();
    for (SystemTable table : tables.listSystemTables(session)) {
        ConnectorTableMetadata tableMetadata = table.getTableMetadata();
        if (prefix.matches(tableMetadata.getTable())) {
            builder.put(tableMetadata.getTable(), tableMetadata.getColumns());
        }
    }
    return builder.build();
}
Also used : ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) PrestoException(com.facebook.presto.spi.PrestoException) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) SystemTable(com.facebook.presto.spi.SystemTable) Collections.singletonMap(java.util.Collections.singletonMap) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Constraint(com.facebook.presto.spi.Constraint) MetadataUtil.findColumnMetadata(com.facebook.presto.metadata.MetadataUtil.findColumnMetadata) String.format(java.lang.String.format) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ColumnHandle(com.facebook.presto.spi.ColumnHandle) SystemColumnHandle.toSystemColumnHandles(com.facebook.presto.connector.system.SystemColumnHandle.toSystemColumnHandles) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) SystemTable(com.facebook.presto.spi.SystemTable) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 12 with SchemaTablePrefix

use of com.facebook.presto.spi.SchemaTablePrefix in project presto by prestodb.

the class AbstractTestHiveClient 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, INVALID_DATABASE), ImmutableList.of());
        assertEquals(metadata.listTableColumns(session, new SchemaTablePrefix(INVALID_DATABASE, INVALID_TABLE)), ImmutableMap.of());
        assertEquals(metadata.listViews(session, INVALID_DATABASE), ImmutableList.of());
        assertEquals(metadata.getViews(session, new SchemaTablePrefix(INVALID_DATABASE, INVALID_TABLE)), ImmutableMap.of());
    }
}
Also used : SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Test(org.testng.annotations.Test)

Example 13 with SchemaTablePrefix

use of com.facebook.presto.spi.SchemaTablePrefix in project presto by prestodb.

the class AbstractTestHiveClient 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(com.facebook.presto.spi.SchemaTablePrefix) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) Test(org.testng.annotations.Test)

Example 14 with SchemaTablePrefix

use of com.facebook.presto.spi.SchemaTablePrefix in project presto by prestodb.

the class TestRaptorMetadata method testListTableColumnsFiltering.

@Test
public void testListTableColumnsFiltering() {
    metadata.createTable(SESSION, getOrdersTable(), false);
    Map<SchemaTableName, List<ColumnMetadata>> filterCatalog = metadata.listTableColumns(SESSION, new SchemaTablePrefix());
    Map<SchemaTableName, List<ColumnMetadata>> filterSchema = metadata.listTableColumns(SESSION, new SchemaTablePrefix("test"));
    Map<SchemaTableName, List<ColumnMetadata>> filterTable = metadata.listTableColumns(SESSION, new SchemaTablePrefix("test", "orders"));
    assertEquals(filterCatalog, filterSchema);
    assertEquals(filterCatalog, filterTable);
}
Also used : SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Test(org.testng.annotations.Test)

Aggregations

SchemaTablePrefix (com.facebook.presto.spi.SchemaTablePrefix)14 SchemaTableName (com.facebook.presto.spi.SchemaTableName)12 Test (org.testng.annotations.Test)10 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)9 ImmutableList (com.google.common.collect.ImmutableList)8 List (java.util.List)8 ConnectorSession (com.facebook.presto.spi.ConnectorSession)6 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ConnectorId (com.facebook.presto.spi.ConnectorId)4 ConnectorViewDefinition (com.facebook.presto.spi.ConnectorViewDefinition)4 ArrayList (java.util.ArrayList)4 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)3 Collectors.toList (java.util.stream.Collectors.toList)3 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)2 MetadataUtil.toSchemaTableName (com.facebook.presto.metadata.MetadataUtil.toSchemaTableName)2 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)2 LinkedHashMap (java.util.LinkedHashMap)2 SystemColumnHandle.toSystemColumnHandles (com.facebook.presto.connector.system.SystemColumnHandle.toSystemColumnHandles)1