Search in sources :

Example 1 with TableNotFoundException

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

the class BridgingHiveMetastore method renameColumn.

@Override
public void renameColumn(String databaseName, String tableName, String oldColumnName, String newColumnName) {
    Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(databaseName, tableName);
    if (!source.isPresent()) {
        throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
    }
    org.apache.hadoop.hive.metastore.api.Table table = source.get();
    for (FieldSchema fieldSchema : table.getPartitionKeys()) {
        if (fieldSchema.getName().equals(oldColumnName)) {
            throw new PrestoException(NOT_SUPPORTED, "Renaming partition columns is not supported");
        }
    }
    for (FieldSchema fieldSchema : table.getSd().getCols()) {
        if (fieldSchema.getName().equals(oldColumnName)) {
            fieldSchema.setName(newColumnName);
        }
    }
    alterTable(databaseName, tableName, table);
}
Also used : MetastoreUtil.toMetastoreApiTable(com.facebook.presto.hive.metastore.MetastoreUtil.toMetastoreApiTable) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException)

Example 2 with TableNotFoundException

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

the class BridgingHiveMetastore method renameTable.

@Override
public void renameTable(String databaseName, String tableName, String newDatabaseName, String newTableName) {
    Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(databaseName, tableName);
    if (!source.isPresent()) {
        throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
    }
    org.apache.hadoop.hive.metastore.api.Table table = source.get();
    table.setDbName(newDatabaseName);
    table.setTableName(newTableName);
    alterTable(databaseName, tableName, table);
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) MetastoreUtil.toMetastoreApiTable(com.facebook.presto.hive.metastore.MetastoreUtil.toMetastoreApiTable) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 3 with TableNotFoundException

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

the class SemiTransactionalHiveMetastore method getTablePrivileges.

public synchronized Set<HivePrivilegeInfo> getTablePrivileges(String user, String databaseName, String tableName) {
    checkReadable();
    SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
    Action<TableAndMore> tableAction = tableActions.get(schemaTableName);
    if (tableAction == null) {
        return delegate.getTablePrivileges(user, databaseName, tableName);
    }
    switch(tableAction.getType()) {
        case ADD:
        case ALTER:
            {
                if (!user.equals(tableAction.getData().getTable().getOwner())) {
                    throw new PrestoException(NOT_SUPPORTED, "Cannot access a table newly created in the transaction with a different user");
                }
                Collection<HivePrivilegeInfo> privileges = tableAction.getData().getPrincipalPrivileges().getUserPrivileges().get(user);
                return ImmutableSet.<HivePrivilegeInfo>builder().addAll(privileges).add(new HivePrivilegeInfo(OWNERSHIP, true)).build();
            }
        case INSERT_EXISTING:
            return delegate.getTablePrivileges(user, databaseName, tableName);
        case DROP:
            throw new TableNotFoundException(schemaTableName);
        default:
            throw new IllegalStateException("Unknown action type");
    }
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Collection(java.util.Collection) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 4 with TableNotFoundException

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

the class InMemoryHiveMetastore method alterTable.

@Override
public synchronized void alterTable(String databaseName, String tableName, Table newTable) {
    SchemaTableName oldName = new SchemaTableName(databaseName, tableName);
    SchemaTableName newName = new SchemaTableName(newTable.getDbName(), newTable.getTableName());
    // if the name did not change, this is a simple schema change
    if (oldName.equals(newName)) {
        if (relations.replace(oldName, newTable) == null) {
            throw new TableNotFoundException(oldName);
        }
        return;
    }
    // remove old table definition and add the new one
    Table table = relations.get(oldName);
    if (table == null) {
        throw new TableNotFoundException(oldName);
    }
    if (relations.putIfAbsent(newName, newTable) != null) {
        throw new TableAlreadyExistsException(newName);
    }
    relations.remove(oldName);
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) TableAlreadyExistsException(com.facebook.presto.hive.TableAlreadyExistsException) Table(org.apache.hadoop.hive.metastore.api.Table) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 5 with TableNotFoundException

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

the class HiveMetadata method getTableMetadata.

private ConnectorTableMetadata getTableMetadata(SchemaTableName tableName) {
    Optional<Table> table = metastore.getTable(tableName.getSchemaName(), tableName.getTableName());
    if (!table.isPresent() || table.get().getTableType().equals(TableType.VIRTUAL_VIEW.name())) {
        throw new TableNotFoundException(tableName);
    }
    Function<HiveColumnHandle, ColumnMetadata> metadataGetter = columnMetadataGetter(table.get(), typeManager);
    ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
    for (HiveColumnHandle columnHandle : hiveColumnHandles(connectorId, table.get())) {
        columns.add(metadataGetter.apply(columnHandle));
    }
    ImmutableMap.Builder<String, Object> properties = ImmutableMap.builder();
    if (table.get().getTableType().equals(EXTERNAL_TABLE.name())) {
        properties.put(EXTERNAL_LOCATION_PROPERTY, table.get().getStorage().getLocation());
    }
    try {
        HiveStorageFormat format = extractHiveStorageFormat(table.get());
        properties.put(STORAGE_FORMAT_PROPERTY, format);
    } catch (PrestoException ignored) {
    // todo fail if format is not known
    }
    List<String> partitionedBy = table.get().getPartitionColumns().stream().map(Column::getName).collect(toList());
    if (!partitionedBy.isEmpty()) {
        properties.put(PARTITIONED_BY_PROPERTY, partitionedBy);
    }
    Optional<HiveBucketProperty> bucketProperty = table.get().getStorage().getBucketProperty();
    if (bucketProperty.isPresent()) {
        properties.put(BUCKET_COUNT_PROPERTY, bucketProperty.get().getBucketCount());
        properties.put(BUCKETED_BY_PROPERTY, bucketProperty.get().getBucketedBy());
    }
    properties.putAll(tableParameterCodec.decode(table.get().getParameters()));
    return new ConnectorTableMetadata(tableName, columns.build(), properties.build());
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Table(com.facebook.presto.hive.metastore.Table) ImmutableList(com.google.common.collect.ImmutableList) PrestoException(com.facebook.presto.spi.PrestoException) ImmutableMap(com.google.common.collect.ImmutableMap) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) HiveTableProperties.getHiveStorageFormat(com.facebook.presto.hive.HiveTableProperties.getHiveStorageFormat) StorageFormat.fromHiveStorageFormat(com.facebook.presto.hive.metastore.StorageFormat.fromHiveStorageFormat) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Aggregations

TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)95 SchemaTableName (com.facebook.presto.spi.SchemaTableName)68 PrestoException (com.facebook.presto.spi.PrestoException)38 Table (com.facebook.presto.hive.metastore.Table)36 ImmutableMap (com.google.common.collect.ImmutableMap)33 MetastoreContext (com.facebook.presto.hive.metastore.MetastoreContext)28 ImmutableList (com.google.common.collect.ImmutableList)28 List (java.util.List)24 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)23 ColumnHandle (com.facebook.presto.spi.ColumnHandle)22 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)20 Constraint (com.facebook.presto.spi.Constraint)20 Map (java.util.Map)20 Set (java.util.Set)20 Optional (java.util.Optional)19 Column (com.facebook.presto.hive.metastore.Column)18 PartitionStatistics (com.facebook.presto.hive.metastore.PartitionStatistics)18 HashSet (java.util.HashSet)18 SystemTable (com.facebook.presto.spi.SystemTable)17 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)17