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);
}
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);
}
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");
}
}
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);
}
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());
}
Aggregations