Search in sources :

Example 31 with TableNotFoundException

use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.

the class HivePartitionManager method getTable.

private Table getTable(SemiTransactionalHiveMetastore metastore, SchemaTableName tableName) {
    Optional<Table> target = metastore.getTable(tableName.getSchemaName(), tableName.getTableName());
    if (!target.isPresent()) {
        throw new TableNotFoundException(tableName);
    }
    Table table = target.get();
    String protectMode = table.getParameters().get(ProtectMode.PARAMETER_NAME);
    if (protectMode != null && getProtectModeFromString(protectMode).offline) {
        throw new TableOfflineException(tableName, false, null);
    }
    String prestoOffline = table.getParameters().get(PRESTO_OFFLINE);
    if (!isNullOrEmpty(prestoOffline)) {
        throw new TableOfflineException(tableName, true, prestoOffline);
    }
    return table;
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Table(com.facebook.presto.hive.metastore.Table) ProtectMode.getProtectModeFromString(org.apache.hadoop.hive.metastore.ProtectMode.getProtectModeFromString)

Example 32 with TableNotFoundException

use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.

the class SemiTransactionalHiveMetastore method finishInsertIntoExistingTable.

public synchronized void finishInsertIntoExistingTable(ConnectorSession session, String databaseName, String tableName, Path currentLocation, List<String> fileNames) {
    // Data can only be inserted into partitions and unpartitioned tables. They can never be inserted into a partitioned table.
    // Therefore, this method assumes that the table is unpartitioned.
    setShared();
    SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
    Action<TableAndMore> oldTableAction = tableActions.get(schemaTableName);
    if (oldTableAction == null) {
        Optional<Table> table = delegate.getTable(databaseName, tableName);
        if (!table.isPresent()) {
            throw new TableNotFoundException(schemaTableName);
        }
        tableActions.put(schemaTableName, new Action<>(ActionType.INSERT_EXISTING, new TableAndMore(table.get(), Optional.empty(), Optional.of(currentLocation), Optional.of(fileNames)), session.getUser(), session.getQueryId()));
        return;
    }
    switch(oldTableAction.getType()) {
        case DROP:
            throw new TableNotFoundException(schemaTableName);
        case ADD:
        case ALTER:
        case INSERT_EXISTING:
            throw new UnsupportedOperationException("Inserting into an unpartitioned table that were added, altered, or inserted into 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 33 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 34 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 35 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)

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