Search in sources :

Example 46 with SchemaTableName

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

the class RaptorMetadata method getTableMetadata.

@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle) {
    RaptorTableHandle handle = (RaptorTableHandle) tableHandle;
    SchemaTableName tableName = new SchemaTableName(handle.getSchemaName(), handle.getTableName());
    List<TableColumn> tableColumns = dao.listTableColumns(handle.getTableId());
    if (tableColumns.isEmpty()) {
        throw new TableNotFoundException(tableName);
    }
    ImmutableMap.Builder<String, Object> properties = ImmutableMap.builder();
    SortedMap<Integer, String> bucketing = new TreeMap<>();
    SortedMap<Integer, String> ordering = new TreeMap<>();
    for (TableColumn column : tableColumns) {
        if (column.isTemporal()) {
            properties.put(TEMPORAL_COLUMN_PROPERTY, column.getColumnName());
        }
        column.getBucketOrdinal().ifPresent(bucketOrdinal -> bucketing.put(bucketOrdinal, column.getColumnName()));
        column.getSortOrdinal().ifPresent(sortOrdinal -> ordering.put(sortOrdinal, column.getColumnName()));
    }
    if (!bucketing.isEmpty()) {
        properties.put(BUCKETED_ON_PROPERTY, ImmutableList.copyOf(bucketing.values()));
    }
    if (!ordering.isEmpty()) {
        properties.put(ORDERING_PROPERTY, ImmutableList.copyOf(ordering.values()));
    }
    handle.getBucketCount().ifPresent(bucketCount -> properties.put(BUCKET_COUNT_PROPERTY, bucketCount));
    handle.getDistributionName().ifPresent(distributionName -> properties.put(DISTRIBUTION_NAME_PROPERTY, distributionName));
    // Only display organization and table_supports_delta_delete property if set
    if (handle.isOrganized()) {
        properties.put(ORGANIZED_PROPERTY, true);
    }
    if (handle.isTableSupportsDeltaDelete()) {
        properties.put(TABLE_SUPPORTS_DELTA_DELETE, true);
    }
    List<ColumnMetadata> columns = tableColumns.stream().map(TableColumn::toColumnMetadata).collect(toCollection(ArrayList::new));
    columns.add(hiddenColumn(SHARD_UUID_COLUMN_NAME, SHARD_UUID_COLUMN_TYPE));
    if (handle.isBucketed()) {
        columns.add(hiddenColumn(BUCKET_NUMBER_COLUMN_NAME, INTEGER));
    }
    properties.putAll(getExtraProperties(handle.getTableId()));
    return new ConnectorTableMetadata(tableName, columns, properties.build());
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) TreeMap(java.util.TreeMap) SchemaTableName(com.facebook.presto.spi.SchemaTableName) TableColumn(com.facebook.presto.raptor.metadata.TableColumn) ImmutableMap(com.google.common.collect.ImmutableMap) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 47 with SchemaTableName

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

the class TestPrometheusRetrieveUpValueIntegrationTests method testCreateTable.

@Test(expectedExceptions = PrestoException.class, dependsOnMethods = "testRetrieveUpValue")
public void testCreateTable() {
    PrometheusMetadata metadata = new PrometheusMetadata(client);
    metadata.createTable(SESSION, new ConnectorTableMetadata(new SchemaTableName("default", "foo"), ImmutableList.of(new ColumnMetadata("text", createUnboundedVarcharType()))), false);
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 48 with SchemaTableName

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

the class AtopMetadata method getColumnMetadata.

@Override
public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle columnHandle) {
    String columnName = ((AtopColumnHandle) columnHandle).getName();
    for (ColumnMetadata column : getTableMetadata(session, tableHandle).getColumns()) {
        if (column.getName().equals(columnName)) {
            return column;
        }
    }
    AtopTableHandle atopTableHandle = (AtopTableHandle) tableHandle;
    SchemaTableName tableName = new SchemaTableName(atopTableHandle.getSchema(), atopTableHandle.getTable().getName());
    throw new ColumnNotFoundException(tableName, columnName);
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ColumnNotFoundException(com.facebook.presto.spi.ColumnNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 49 with SchemaTableName

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

the class AtopMetadata method getTableMetadata.

@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle) {
    AtopTableHandle atopTableHandle = (AtopTableHandle) tableHandle;
    ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
    for (AtopColumn column : atopTableHandle.getTable().getColumns()) {
        columns.add(new ColumnMetadata(column.getName(), typeManager.getType(column.getType())));
    }
    SchemaTableName schemaTableName = new SchemaTableName(atopTableHandle.getSchema(), atopTableHandle.getTable().getName());
    return new ConnectorTableMetadata(schemaTableName, columns.build());
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) AtopColumn(com.facebook.presto.atop.AtopTable.AtopColumn) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 50 with SchemaTableName

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

the class AtopMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
    for (SchemaTableName tableName : listTables(session, prefix.getSchemaName())) {
        ConnectorTableMetadata tableMetadata = getTableMetadata(session, getTableHandle(session, tableName));
        columns.put(tableName, tableMetadata.getColumns());
    }
    return columns.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Aggregations

SchemaTableName (com.facebook.presto.spi.SchemaTableName)370 ImmutableList (com.google.common.collect.ImmutableList)122 Test (org.testng.annotations.Test)107 List (java.util.List)100 PrestoException (com.facebook.presto.spi.PrestoException)99 ImmutableMap (com.google.common.collect.ImmutableMap)95 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)91 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)79 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)73 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)68 ConnectorSession (com.facebook.presto.spi.ConnectorSession)62 ArrayList (java.util.ArrayList)60 ColumnHandle (com.facebook.presto.spi.ColumnHandle)58 Table (com.facebook.presto.hive.metastore.Table)57 Map (java.util.Map)57 Optional (java.util.Optional)55 Column (com.facebook.presto.hive.metastore.Column)52 Collectors.toList (java.util.stream.Collectors.toList)48 Path (org.apache.hadoop.fs.Path)47 Objects.requireNonNull (java.util.Objects.requireNonNull)46