Search in sources :

Example 11 with TableAlreadyExistsException

use of com.facebook.presto.hive.TableAlreadyExistsException in project presto by prestodb.

the class SemiTransactionalHiveMetastore method createTable.

/**
 * {@code currentLocation} needs to be supplied if a writePath exists for the table.
 */
public synchronized void createTable(ConnectorSession session, Table table, PrincipalPrivileges principalPrivileges, Optional<Path> currentPath, boolean ignoreExisting, PartitionStatistics statistics) {
    setShared();
    // When creating a table, it should never have partition actions. This is just a sanity check.
    checkNoPartitionAction(table.getDatabaseName(), table.getTableName());
    Action<TableAndMore> oldTableAction = tableActions.get(table.getSchemaTableName());
    TableAndMore tableAndMore = new TableAndMore(table, Optional.of(principalPrivileges), currentPath, Optional.empty(), ignoreExisting, statistics, statistics);
    if (oldTableAction == null) {
        HdfsContext context = new HdfsContext(session, table.getDatabaseName(), table.getTableName(), table.getStorage().getLocation(), true);
        tableActions.put(table.getSchemaTableName(), new Action<>(ActionType.ADD, tableAndMore, context));
        return;
    }
    switch(oldTableAction.getType()) {
        case DROP:
            throw new PrestoException(TRANSACTION_CONFLICT, "Dropping and then recreating the same table in a transaction is not supported");
        case ADD:
        case ALTER:
        case INSERT_EXISTING:
            throw new TableAlreadyExistsException(table.getSchemaTableName());
        default:
            throw new IllegalStateException("Unknown action type");
    }
}
Also used : TableAlreadyExistsException(com.facebook.presto.hive.TableAlreadyExistsException) PrestoException(com.facebook.presto.spi.PrestoException) HdfsContext(com.facebook.presto.hive.HdfsContext)

Aggregations

TableAlreadyExistsException (com.facebook.presto.hive.TableAlreadyExistsException)11 SchemaTableName (com.facebook.presto.spi.SchemaTableName)10 PrestoException (com.facebook.presto.spi.PrestoException)5 Table (org.apache.hadoop.hive.metastore.api.Table)4 File (java.io.File)3 Path (org.apache.hadoop.fs.Path)3 TableType (org.apache.hadoop.hive.metastore.TableType)3 HdfsContext (com.facebook.presto.hive.HdfsContext)2 IcebergTableProperties.getFileFormat (com.facebook.presto.iceberg.IcebergTableProperties.getFileFormat)2 SchemaNotFoundException (com.facebook.presto.spi.SchemaNotFoundException)2 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)2 PrincipalPrivilegeSet (org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet)2 FileFormat (org.apache.iceberg.FileFormat)2 PartitionSpec (org.apache.iceberg.PartitionSpec)2 Schema (org.apache.iceberg.Schema)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AlreadyExistsException (com.amazonaws.services.glue.model.AlreadyExistsException)1 CreateTableRequest (com.amazonaws.services.glue.model.CreateTableRequest)1