use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class SemiTransactionalHiveMetastore method truncateUnpartitionedTable.
public synchronized void truncateUnpartitionedTable(ConnectorSession session, String databaseName, String tableName) {
checkReadable();
Optional<Table> table = getTable(databaseName, tableName);
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
if (!table.isPresent()) {
throw new TableNotFoundException(schemaTableName);
}
if (!table.get().getTableType().equals(MANAGED_TABLE.toString())) {
throw new PrestoException(NOT_SUPPORTED, "Cannot delete from non-managed Hive table");
}
if (!table.get().getPartitionColumns().isEmpty()) {
throw new IllegalArgumentException("Table is partitioned");
}
Path path = new Path(table.get().getStorage().getLocation());
String user = session.getUser();
setExclusive((delegate, hdfsEnvironment) -> {
RecursiveDeleteResult recursiveDeleteResult = recursiveDeleteFiles(hdfsEnvironment, user, path, ImmutableList.of(""), false);
if (!recursiveDeleteResult.getNotDeletedEligibleItems().isEmpty()) {
throw new PrestoException(HIVE_FILESYSTEM_ERROR, format("Error deleting from unpartitioned table %s. These items can not be deleted: %s", schemaTableName, recursiveDeleteResult.getNotDeletedEligibleItems()));
}
});
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class SemiTransactionalHiveMetastore method dropTable.
public synchronized void dropTable(ConnectorSession session, String databaseName, String tableName) {
setShared();
// Dropping table with partition actions requires cleaning up staging data, which is not implemented yet.
checkNoPartitionAction(databaseName, tableName);
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
Action<TableAndMore> oldTableAction = tableActions.get(schemaTableName);
if (oldTableAction == null || oldTableAction.getType() == ActionType.ALTER) {
tableActions.put(schemaTableName, new Action<>(ActionType.DROP, null, session.getUser(), session.getQueryId()));
return;
}
switch(oldTableAction.getType()) {
case DROP:
throw new TableNotFoundException(schemaTableName);
case ADD:
case ALTER:
case INSERT_EXISTING:
throw new UnsupportedOperationException("dropping a table added/modified in the same transaction is not supported");
default:
throw new IllegalStateException("Unknown action type");
}
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class BridgingHiveMetastore method addColumn.
@Override
public void addColumn(String databaseName, String tableName, String columnName, HiveType columnType, String columnComment) {
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.getSd().getCols().add(new FieldSchema(columnName, columnType.getHiveTypeName(), columnComment));
alterTable(databaseName, tableName, table);
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class BaseJdbcClient method getColumns.
@Override
public List<JdbcColumnHandle> getColumns(JdbcTableHandle tableHandle) {
try (Connection connection = driver.connect(connectionUrl, connectionProperties)) {
try (ResultSet resultSet = getColumns(tableHandle, connection.getMetaData())) {
List<JdbcColumnHandle> columns = new ArrayList<>();
boolean found = false;
while (resultSet.next()) {
found = true;
Type columnType = toPrestoType(resultSet.getInt("DATA_TYPE"), resultSet.getInt("COLUMN_SIZE"));
// skip unsupported column types
if (columnType != null) {
String columnName = resultSet.getString("COLUMN_NAME");
columns.add(new JdbcColumnHandle(connectorId, columnName, columnType));
}
}
if (!found) {
throw new TableNotFoundException(tableHandle.getSchemaTableName());
}
if (columns.isEmpty()) {
throw new PrestoException(NOT_SUPPORTED, "Table has no supported column types: " + tableHandle.getSchemaTableName());
}
return ImmutableList.copyOf(columns);
}
} catch (SQLException e) {
throw new PrestoException(JDBC_ERROR, e);
}
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class JdbcMetadata method listTableColumns.
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
List<SchemaTableName> tables;
if (prefix.getTableName() != null) {
tables = ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName()));
} else {
tables = listTables(session, prefix.getSchemaName());
}
for (SchemaTableName tableName : tables) {
try {
JdbcTableHandle tableHandle = jdbcClient.getTableHandle(tableName);
if (tableHandle == null) {
continue;
}
columns.put(tableName, getTableMetadata(session, tableHandle).getColumns());
} catch (TableNotFoundException e) {
// table disappeared during listing operation
}
}
return columns.build();
}
Aggregations