Search in sources :

Example 26 with TableNotFoundException

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()));
        }
    });
}
Also used : Path(org.apache.hadoop.fs.Path) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 27 with TableNotFoundException

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");
    }
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 28 with TableNotFoundException

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);
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) MetastoreUtil.toMetastoreApiTable(com.facebook.presto.hive.metastore.MetastoreUtil.toMetastoreApiTable) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 29 with TableNotFoundException

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);
    }
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) CharType.createCharType(com.facebook.presto.spi.type.CharType.createCharType) VarcharType.createVarcharType(com.facebook.presto.spi.type.VarcharType.createVarcharType) Type(com.facebook.presto.spi.type.Type) CharType(com.facebook.presto.spi.type.CharType) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(com.facebook.presto.spi.type.VarcharType) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PrestoException(com.facebook.presto.spi.PrestoException)

Example 30 with TableNotFoundException

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();
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)39 SchemaTableName (com.facebook.presto.spi.SchemaTableName)26 PrestoException (com.facebook.presto.spi.PrestoException)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 ColumnHandle (com.facebook.presto.spi.ColumnHandle)8 Table (com.facebook.presto.hive.metastore.Table)7 ImmutableList (com.google.common.collect.ImmutableList)6 ArrayList (java.util.ArrayList)6 List (java.util.List)5 AccumuloTable (com.facebook.presto.accumulo.metadata.AccumuloTable)4 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)4 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)4 Constraint (com.facebook.presto.spi.Constraint)4 Slice (io.airlift.slice.Slice)4 Collectors.toList (java.util.stream.Collectors.toList)4 Path (org.apache.hadoop.fs.Path)4 AccumuloTableHandle (com.facebook.presto.accumulo.model.AccumuloTableHandle)3 HiveTableProperties.getHiveStorageFormat (com.facebook.presto.hive.HiveTableProperties.getHiveStorageFormat)3 Table (org.apache.hadoop.hive.metastore.api.Table)3 AccumuloColumnHandle (com.facebook.presto.accumulo.model.AccumuloColumnHandle)2