Search in sources :

Example 21 with TableNotFoundException

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

the class NativeCassandraSession method getTableMetadata.

private TableMetadata getTableMetadata(SchemaTableName schemaTableName) {
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();
    KeyspaceMetadata keyspaceMetadata = getCheckedKeyspaceMetadata(schemaName);
    TableMetadata tableMetadata = keyspaceMetadata.getTable(tableName);
    if (tableMetadata != null) {
        return tableMetadata;
    }
    for (TableMetadata table : keyspaceMetadata.getTables()) {
        if (table.getName().equalsIgnoreCase(tableName)) {
            return table;
        }
    }
    throw new TableNotFoundException(schemaTableName);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 22 with TableNotFoundException

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

the class HiveMetadata method dropTable.

@Override
public void dropTable(ConnectorSession session, ConnectorTableHandle tableHandle) {
    HiveTableHandle handle = (HiveTableHandle) tableHandle;
    SchemaTableName tableName = schemaTableName(tableHandle);
    Optional<Table> target = metastore.getTable(handle.getSchemaName(), handle.getTableName());
    if (!target.isPresent()) {
        throw new TableNotFoundException(tableName);
    }
    metastore.dropTable(session, handle.getSchemaName(), handle.getTableName());
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Table(com.facebook.presto.hive.metastore.Table) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 23 with TableNotFoundException

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

the class HiveMetadata method finishInsert.

@Override
public Optional<ConnectorOutputMetadata> finishInsert(ConnectorSession session, ConnectorInsertTableHandle insertHandle, Collection<Slice> fragments) {
    HiveInsertTableHandle handle = (HiveInsertTableHandle) insertHandle;
    List<PartitionUpdate> partitionUpdates = fragments.stream().map(Slice::getBytes).map(partitionUpdateCodec::fromJson).collect(toList());
    HiveStorageFormat tableStorageFormat = handle.getTableStorageFormat();
    partitionUpdates = PartitionUpdate.mergePartitionUpdates(partitionUpdates);
    Optional<Table> table = metastore.getTable(handle.getSchemaName(), handle.getTableName());
    if (!table.isPresent()) {
        throw new TableNotFoundException(new SchemaTableName(handle.getSchemaName(), handle.getTableName()));
    }
    if (!table.get().getStorage().getStorageFormat().getInputFormat().equals(tableStorageFormat.getInputFormat()) && respectTableFormat) {
        throw new PrestoException(HIVE_CONCURRENT_MODIFICATION_DETECTED, "Table format changed during insert");
    }
    if (handle.getBucketProperty().isPresent()) {
        ImmutableList<PartitionUpdate> partitionUpdatesForMissingBuckets = computePartitionUpdatesForMissingBuckets(handle, table.get(), partitionUpdates);
        // replace partitionUpdates before creating the empty files so that those files will be cleaned up if we end up rollback
        partitionUpdates = PartitionUpdate.mergePartitionUpdates(Iterables.concat(partitionUpdates, partitionUpdatesForMissingBuckets));
        for (PartitionUpdate partitionUpdate : partitionUpdatesForMissingBuckets) {
            Optional<Partition> partition = table.get().getPartitionColumns().isEmpty() ? Optional.empty() : Optional.of(buildPartitionObject(session.getQueryId(), table.get(), partitionUpdate));
            createEmptyFile(partitionUpdate.getWritePath(), table.get(), partition, partitionUpdate.getFileNames());
        }
    }
    for (PartitionUpdate partitionUpdate : partitionUpdates) {
        if (partitionUpdate.getName().isEmpty()) {
            // insert into unpartitioned table
            metastore.finishInsertIntoExistingTable(session, handle.getSchemaName(), handle.getTableName(), partitionUpdate.getWritePath(), partitionUpdate.getFileNames());
        } else if (!partitionUpdate.isNew()) {
            // insert into existing partition
            metastore.finishInsertIntoExistingPartition(session, handle.getSchemaName(), handle.getTableName(), toPartitionValues(partitionUpdate.getName()), partitionUpdate.getWritePath(), partitionUpdate.getFileNames());
        } else {
            // insert into new partition
            Partition partition = buildPartitionObject(session.getQueryId(), table.get(), partitionUpdate);
            if (!partition.getStorage().getStorageFormat().getInputFormat().equals(handle.getPartitionStorageFormat().getInputFormat()) && respectTableFormat) {
                throw new PrestoException(HIVE_CONCURRENT_MODIFICATION_DETECTED, "Partition format changed during insert");
            }
            metastore.addPartition(session, handle.getSchemaName(), handle.getTableName(), partition, partitionUpdate.getWritePath());
        }
    }
    return Optional.of(new HiveWrittenPartitions(partitionUpdates.stream().map(PartitionUpdate::getName).collect(Collectors.toList())));
}
Also used : Partition(com.facebook.presto.hive.metastore.Partition) Table(com.facebook.presto.hive.metastore.Table) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) HiveTableProperties.getHiveStorageFormat(com.facebook.presto.hive.HiveTableProperties.getHiveStorageFormat) StorageFormat.fromHiveStorageFormat(com.facebook.presto.hive.metastore.StorageFormat.fromHiveStorageFormat) Slice(io.airlift.slice.Slice)

Example 24 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 25 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)

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