Search in sources :

Example 1 with SchemaTableName

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

the class BridgingHiveMetastore method renameColumn.

@Override
public void renameColumn(String databaseName, String tableName, String oldColumnName, String newColumnName) {
    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();
    for (FieldSchema fieldSchema : table.getPartitionKeys()) {
        if (fieldSchema.getName().equals(oldColumnName)) {
            throw new PrestoException(NOT_SUPPORTED, "Renaming partition columns is not supported");
        }
    }
    for (FieldSchema fieldSchema : table.getSd().getCols()) {
        if (fieldSchema.getName().equals(oldColumnName)) {
            fieldSchema.setName(newColumnName);
        }
    }
    alterTable(databaseName, tableName, table);
}
Also used : MetastoreUtil.toMetastoreApiTable(com.facebook.presto.hive.metastore.MetastoreUtil.toMetastoreApiTable) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException)

Example 2 with SchemaTableName

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

the class SemiTransactionalHiveMetastore method finishInsertIntoExistingPartition.

public synchronized void finishInsertIntoExistingPartition(ConnectorSession session, String databaseName, String tableName, List<String> partitionValues, Path currentLocation, List<String> fileNames) {
    setShared();
    SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
    Map<List<String>, Action<PartitionAndMore>> partitionActionsOfTable = partitionActions.computeIfAbsent(schemaTableName, k -> new HashMap<>());
    Action<PartitionAndMore> oldPartitionAction = partitionActionsOfTable.get(partitionValues);
    if (oldPartitionAction == null) {
        Optional<Partition> partition = delegate.getPartition(databaseName, tableName, partitionValues);
        if (!partition.isPresent()) {
            throw new PartitionNotFoundException(schemaTableName, partitionValues);
        }
        partitionActionsOfTable.put(partitionValues, new Action<>(ActionType.INSERT_EXISTING, new PartitionAndMore(partition.get(), currentLocation, Optional.of(fileNames)), session.getUser(), session.getQueryId()));
        return;
    }
    switch(oldPartitionAction.getType()) {
        case DROP:
            throw new PartitionNotFoundException(schemaTableName, partitionValues);
        case ADD:
        case ALTER:
        case INSERT_EXISTING:
            throw new UnsupportedOperationException("Inserting into a partition that were added, altered, or inserted into in the same transaction is not supported");
        default:
            throw new IllegalStateException("Unknown action type");
    }
}
Also used : SchemaTableName(com.facebook.presto.spi.SchemaTableName) PartitionNotFoundException(com.facebook.presto.hive.PartitionNotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList)

Example 3 with SchemaTableName

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

the class BridgingHiveMetastore method renameTable.

@Override
public void renameTable(String databaseName, String tableName, String newDatabaseName, String newTableName) {
    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.setDbName(newDatabaseName);
    table.setTableName(newTableName);
    alterTable(databaseName, tableName, table);
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) MetastoreUtil.toMetastoreApiTable(com.facebook.presto.hive.metastore.MetastoreUtil.toMetastoreApiTable) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 4 with SchemaTableName

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

the class SemiTransactionalHiveMetastore method getTable.

public synchronized Optional<Table> getTable(String databaseName, String tableName) {
    checkReadable();
    Action<TableAndMore> tableAction = tableActions.get(new SchemaTableName(databaseName, tableName));
    if (tableAction == null) {
        return delegate.getTable(databaseName, tableName);
    }
    switch(tableAction.getType()) {
        case ADD:
        case ALTER:
        case INSERT_EXISTING:
            return Optional.of(tableAction.getData().getTable());
        case DROP:
            return Optional.empty();
        default:
            throw new IllegalStateException("Unknown action type");
    }
}
Also used : SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 5 with SchemaTableName

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

the class SemiTransactionalHiveMetastore method getPartition.

public synchronized Optional<Partition> getPartition(String databaseName, String tableName, List<String> partitionValues) {
    checkReadable();
    TableSource tableSource = getTableSource(databaseName, tableName);
    Map<List<String>, Action<PartitionAndMore>> partitionActionsOfTable = partitionActions.computeIfAbsent(new SchemaTableName(databaseName, tableName), k -> new HashMap<>());
    Action<PartitionAndMore> partitionAction = partitionActionsOfTable.get(partitionValues);
    if (partitionAction != null) {
        return getPartitionFromPartitionAction(partitionAction);
    }
    switch(tableSource) {
        case PRE_EXISTING_TABLE:
            return delegate.getPartition(databaseName, tableName, partitionValues);
        case CREATED_IN_THIS_TRANSACTION:
            return Optional.empty();
        default:
            throw new UnsupportedOperationException("unknown table source");
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Aggregations

SchemaTableName (com.facebook.presto.spi.SchemaTableName)370 ImmutableList (com.google.common.collect.ImmutableList)122 Test (org.testng.annotations.Test)107 List (java.util.List)100 PrestoException (com.facebook.presto.spi.PrestoException)99 ImmutableMap (com.google.common.collect.ImmutableMap)95 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)91 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)79 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)73 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)68 ConnectorSession (com.facebook.presto.spi.ConnectorSession)62 ArrayList (java.util.ArrayList)60 ColumnHandle (com.facebook.presto.spi.ColumnHandle)58 Table (com.facebook.presto.hive.metastore.Table)57 Map (java.util.Map)57 Optional (java.util.Optional)55 Column (com.facebook.presto.hive.metastore.Column)52 Collectors.toList (java.util.stream.Collectors.toList)48 Path (org.apache.hadoop.fs.Path)47 Objects.requireNonNull (java.util.Objects.requireNonNull)46