Search in sources :

Example 1 with TableAlreadyExistsException

use of io.prestosql.spi.connector.TableAlreadyExistsException in project hetu-core by openlookeng.

the class InMemoryThriftMetastore method createTable.

@Override
public synchronized void createTable(HiveIdentity identity, Table table) {
    TableType tableType = TableType.valueOf(table.getTableType());
    checkArgument(EnumSet.of(MANAGED_TABLE, EXTERNAL_TABLE, VIRTUAL_VIEW).contains(tableType), "Invalid table type: %s", tableType);
    if (tableType == VIRTUAL_VIEW) {
        checkArgument(table.getSd().getLocation() == null, "Storage location for view must be null");
    } else {
        File directory = new File(new Path(table.getSd().getLocation()).toUri());
        checkArgument(directory.exists(), "Table directory does not exist");
        if (tableType == MANAGED_TABLE) {
            checkArgument(isParentDir(directory, baseDirectory), "Table directory must be inside of the metastore base directory");
        }
    }
    SchemaTableName schemaTableName = new SchemaTableName(table.getDbName(), table.getTableName());
    Table tableCopy = table.deepCopy();
    if (relations.putIfAbsent(schemaTableName, tableCopy) != null) {
        throw new TableAlreadyExistsException(schemaTableName);
    }
    if (tableType == VIRTUAL_VIEW) {
        views.put(schemaTableName, tableCopy);
    }
    PrincipalPrivilegeSet privileges = table.getPrivileges();
    if (privileges != null) {
        throw new UnsupportedOperationException();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) TableAlreadyExistsException(io.prestosql.spi.connector.TableAlreadyExistsException) TableType(org.apache.hadoop.hive.metastore.TableType) Table(org.apache.hadoop.hive.metastore.api.Table) PrincipalPrivilegeSet(org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet) File(java.io.File) SchemaTableName(io.prestosql.spi.connector.SchemaTableName)

Example 2 with TableAlreadyExistsException

use of io.prestosql.spi.connector.TableAlreadyExistsException in project hetu-core by openlookeng.

the class GlueHiveMetastore method createTable.

@Override
public void createTable(HiveIdentity identity, Table table, PrincipalPrivileges principalPrivileges) {
    try {
        TableInput input = GlueInputConverter.convertTable(table);
        glueClient.createTable(new CreateTableRequest().withCatalogId(catalogId).withDatabaseName(table.getDatabaseName()).withTableInput(input));
    } catch (AlreadyExistsException e) {
        throw new TableAlreadyExistsException(new SchemaTableName(table.getDatabaseName(), table.getTableName()));
    } catch (EntityNotFoundException e) {
        throw new SchemaNotFoundException(table.getDatabaseName());
    } catch (AmazonServiceException e) {
        throw new PrestoException(HiveErrorCode.HIVE_METASTORE_ERROR, e);
    }
}
Also used : TableInput(com.amazonaws.services.glue.model.TableInput) TableAlreadyExistsException(io.prestosql.spi.connector.TableAlreadyExistsException) TableAlreadyExistsException(io.prestosql.spi.connector.TableAlreadyExistsException) SchemaAlreadyExistsException(io.prestosql.spi.connector.SchemaAlreadyExistsException) AlreadyExistsException(com.amazonaws.services.glue.model.AlreadyExistsException) AmazonServiceException(com.amazonaws.AmazonServiceException) PrestoException(io.prestosql.spi.PrestoException) EntityNotFoundException(com.amazonaws.services.glue.model.EntityNotFoundException) SchemaNotFoundException(io.prestosql.spi.connector.SchemaNotFoundException) CreateTableRequest(com.amazonaws.services.glue.model.CreateTableRequest) SchemaTableName(io.prestosql.spi.connector.SchemaTableName)

Example 3 with TableAlreadyExistsException

use of io.prestosql.spi.connector.TableAlreadyExistsException in project hetu-core by openlookeng.

the class HiveMetadata method createView.

@Override
public void createView(ConnectorSession session, SchemaTableName viewName, ConnectorViewDefinition definition, boolean replace) {
    HiveIdentity identity = new HiveIdentity(session);
    Map<String, String> properties = ImmutableMap.<String, String>builder().put(TABLE_COMMENT, "Presto View").put(PRESTO_VIEW_FLAG, "true").put(PRESTO_VERSION_NAME, prestoVersion).put(PRESTO_QUERY_ID_NAME, session.getQueryId()).build();
    Column dummyColumn = new Column("dummy", HiveType.HIVE_STRING, Optional.empty());
    Table.Builder tableBuilder = Table.builder().setDatabaseName(viewName.getSchemaName()).setTableName(viewName.getTableName()).setOwner(session.getUser()).setTableType(TableType.VIRTUAL_VIEW.name()).setDataColumns(ImmutableList.of(dummyColumn)).setPartitionColumns(ImmutableList.of()).setParameters(properties).setViewOriginalText(Optional.of(encodeViewData(definition))).setViewExpandedText(Optional.of("/* Presto View */"));
    tableBuilder.getStorageBuilder().setStorageFormat(StorageFormat.VIEW_STORAGE_FORMAT).setLocation("");
    Table table = tableBuilder.build();
    PrincipalPrivileges principalPrivileges = MetastoreUtil.buildInitialPrivilegeSet(session.getUser());
    Optional<Table> existing = metastore.getTable(identity, viewName.getSchemaName(), viewName.getTableName());
    if (existing.isPresent()) {
        if (!replace || !HiveUtil.isPrestoView(existing.get())) {
            throw new ViewAlreadyExistsException(viewName);
        }
        metastore.replaceView(identity, viewName.getSchemaName(), viewName.getTableName(), table, principalPrivileges);
        return;
    }
    try {
        metastore.createTable(session, table, principalPrivileges, Optional.empty(), false, new PartitionStatistics(HiveBasicStatistics.createEmptyStatistics(), ImmutableMap.of()));
    } catch (TableAlreadyExistsException e) {
        throw new ViewAlreadyExistsException(e.getTableName());
    }
}
Also used : TableAlreadyExistsException(io.prestosql.spi.connector.TableAlreadyExistsException) SystemTable(io.prestosql.spi.connector.SystemTable) Table(io.prestosql.plugin.hive.metastore.Table) HiveTableProperties.isExternalTable(io.prestosql.plugin.hive.HiveTableProperties.isExternalTable) PrincipalPrivileges(io.prestosql.plugin.hive.metastore.PrincipalPrivileges) SortingColumn(io.prestosql.plugin.hive.metastore.SortingColumn) Column(io.prestosql.plugin.hive.metastore.Column) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity)

Example 4 with TableAlreadyExistsException

use of io.prestosql.spi.connector.TableAlreadyExistsException in project hetu-core by openlookeng.

the class InMemoryThriftMetastore method alterTable.

@Override
public synchronized void alterTable(HiveIdentity identity, 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(io.prestosql.spi.connector.TableNotFoundException) TableAlreadyExistsException(io.prestosql.spi.connector.TableAlreadyExistsException) Table(org.apache.hadoop.hive.metastore.api.Table) SchemaTableName(io.prestosql.spi.connector.SchemaTableName)

Example 5 with TableAlreadyExistsException

use of io.prestosql.spi.connector.TableAlreadyExistsException in project hetu-core by openlookeng.

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());
    HiveIdentity identity = new HiveIdentity(session);
    TableAndMore tableAndMore = new TableAndMore(table, identity, Optional.of(principalPrivileges), currentPath, Optional.empty(), ignoreExisting, statistics, statistics, HiveSessionProperties.isCollectColumnStatisticsOnWrite(session));
    if (oldTableAction == null) {
        HdfsContext hdfsContext = new HdfsContext(session, table.getDatabaseName(), table.getTableName());
        tableActions.put(table.getSchemaTableName(), new Action<>(ActionType.ADD, tableAndMore, hdfsContext, identity));
        return;
    }
    switch(oldTableAction.getType()) {
        case DROP:
            if (!oldTableAction.getHdfsContext().getIdentity().getUser().equals(session.getUser())) {
                throw new PrestoException(TRANSACTION_CONFLICT, "Operation on the same table with different user in the same transaction is not supported");
            }
            HdfsContext hdfsContext = new HdfsContext(session, table.getDatabaseName(), table.getTableName());
            tableActions.put(table.getSchemaTableName(), new Action<>(ActionType.ALTER, tableAndMore, hdfsContext, identity));
            break;
        case ADD:
        case ALTER:
        case INSERT_EXISTING:
            throw new TableAlreadyExistsException(table.getSchemaTableName());
        default:
            throw new IllegalStateException("Unknown action type");
    }
}
Also used : TableAlreadyExistsException(io.prestosql.spi.connector.TableAlreadyExistsException) PrestoException(io.prestosql.spi.PrestoException) HdfsContext(io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity)

Aggregations

TableAlreadyExistsException (io.prestosql.spi.connector.TableAlreadyExistsException)5 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)3 HiveIdentity (io.prestosql.plugin.hive.authentication.HiveIdentity)2 PrestoException (io.prestosql.spi.PrestoException)2 Table (org.apache.hadoop.hive.metastore.api.Table)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AlreadyExistsException (com.amazonaws.services.glue.model.AlreadyExistsException)1 CreateTableRequest (com.amazonaws.services.glue.model.CreateTableRequest)1 EntityNotFoundException (com.amazonaws.services.glue.model.EntityNotFoundException)1 TableInput (com.amazonaws.services.glue.model.TableInput)1 HdfsContext (io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext)1 HiveTableProperties.isExternalTable (io.prestosql.plugin.hive.HiveTableProperties.isExternalTable)1 Column (io.prestosql.plugin.hive.metastore.Column)1 PrincipalPrivileges (io.prestosql.plugin.hive.metastore.PrincipalPrivileges)1 SortingColumn (io.prestosql.plugin.hive.metastore.SortingColumn)1 Table (io.prestosql.plugin.hive.metastore.Table)1 SchemaAlreadyExistsException (io.prestosql.spi.connector.SchemaAlreadyExistsException)1 SchemaNotFoundException (io.prestosql.spi.connector.SchemaNotFoundException)1 SystemTable (io.prestosql.spi.connector.SystemTable)1 TableNotFoundException (io.prestosql.spi.connector.TableNotFoundException)1