use of com.facebook.presto.spi.SchemaTableName 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.SchemaTableName in project presto by prestodb.
the class SemiTransactionalHiveMetastore method finishInsertIntoExistingPartition.
public synchronized void finishInsertIntoExistingPartition(ConnectorSession session, String databaseName, String tableName, List<String> partitionValues, Path currentLocation, List<String> fileNames) {
setShared();
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
Map<List<String>, Action<PartitionAndMore>> partitionActionsOfTable = partitionActions.computeIfAbsent(schemaTableName, k -> new HashMap<>());
Action<PartitionAndMore> oldPartitionAction = partitionActionsOfTable.get(partitionValues);
if (oldPartitionAction == null) {
Optional<Partition> partition = delegate.getPartition(databaseName, tableName, partitionValues);
if (!partition.isPresent()) {
throw new PartitionNotFoundException(schemaTableName, partitionValues);
}
partitionActionsOfTable.put(partitionValues, new Action<>(ActionType.INSERT_EXISTING, new PartitionAndMore(partition.get(), currentLocation, Optional.of(fileNames)), session.getUser(), session.getQueryId()));
return;
}
switch(oldPartitionAction.getType()) {
case DROP:
throw new PartitionNotFoundException(schemaTableName, partitionValues);
case ADD:
case ALTER:
case INSERT_EXISTING:
throw new UnsupportedOperationException("Inserting into a partition that were added, altered, or inserted into in the same transaction is not supported");
default:
throw new IllegalStateException("Unknown action type");
}
}
use of com.facebook.presto.spi.SchemaTableName 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.SchemaTableName in project presto by prestodb.
the class SemiTransactionalHiveMetastore method getTable.
public synchronized Optional<Table> getTable(String databaseName, String tableName) {
checkReadable();
Action<TableAndMore> tableAction = tableActions.get(new SchemaTableName(databaseName, tableName));
if (tableAction == null) {
return delegate.getTable(databaseName, tableName);
}
switch(tableAction.getType()) {
case ADD:
case ALTER:
case INSERT_EXISTING:
return Optional.of(tableAction.getData().getTable());
case DROP:
return Optional.empty();
default:
throw new IllegalStateException("Unknown action type");
}
}
use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.
the class SemiTransactionalHiveMetastore method getPartition.
public synchronized Optional<Partition> getPartition(String databaseName, String tableName, List<String> partitionValues) {
checkReadable();
TableSource tableSource = getTableSource(databaseName, tableName);
Map<List<String>, Action<PartitionAndMore>> partitionActionsOfTable = partitionActions.computeIfAbsent(new SchemaTableName(databaseName, tableName), k -> new HashMap<>());
Action<PartitionAndMore> partitionAction = partitionActionsOfTable.get(partitionValues);
if (partitionAction != null) {
return getPartitionFromPartitionAction(partitionAction);
}
switch(tableSource) {
case PRE_EXISTING_TABLE:
return delegate.getPartition(databaseName, tableName, partitionValues);
case CREATED_IN_THIS_TRANSACTION:
return Optional.empty();
default:
throw new UnsupportedOperationException("unknown table source");
}
}
Aggregations