Search in sources :

Example 6 with AccumuloTable

use of com.facebook.presto.accumulo.metadata.AccumuloTable in project presto by prestodb.

the class AccumuloClient method renameTable.

public void renameTable(SchemaTableName oldName, SchemaTableName newName) {
    if (!oldName.getSchemaName().equals(newName.getSchemaName())) {
        throw new PrestoException(NOT_SUPPORTED, "Accumulo does not support renaming tables to different namespaces (schemas)");
    }
    AccumuloTable oldTable = getTable(oldName);
    if (oldTable == null) {
        throw new TableNotFoundException(oldName);
    }
    AccumuloTable newTable = new AccumuloTable(oldTable.getSchema(), newName.getTableName(), oldTable.getColumns(), oldTable.getRowId(), oldTable.isExternal(), oldTable.getSerializerClassName(), oldTable.getScanAuthorizations());
    // Validate table existence
    if (!tableManager.exists(oldTable.getFullTableName())) {
        throw new PrestoException(ACCUMULO_TABLE_DNE, format("Table %s does not exist", oldTable.getFullTableName()));
    }
    if (tableManager.exists(newTable.getFullTableName())) {
        throw new PrestoException(ACCUMULO_TABLE_EXISTS, format("Table %s already exists", newTable.getFullTableName()));
    }
    // Rename index tables (which will also validate table existence)
    renameIndexTables(oldTable, newTable);
    // Rename the Accumulo table
    tableManager.renameAccumuloTable(oldTable.getFullTableName(), newTable.getFullTableName());
    // We'll then create the metadata
    metaManager.deleteTableMetadata(oldTable.getSchemaTableName());
    metaManager.createTableMetadata(newTable);
}
Also used : AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) PrestoException(com.facebook.presto.spi.PrestoException)

Example 7 with AccumuloTable

use of com.facebook.presto.accumulo.metadata.AccumuloTable in project presto by prestodb.

the class AccumuloClient method renameColumn.

public void renameColumn(AccumuloTable table, String source, String target) {
    if (!table.getColumns().stream().anyMatch(columnHandle -> columnHandle.getName().equalsIgnoreCase(source))) {
        throw new PrestoException(NOT_FOUND, format("Failed to find source column %s to rename to %s", source, target));
    }
    // Copy existing column list, replacing the old column name with the new
    ImmutableList.Builder<AccumuloColumnHandle> newColumnList = ImmutableList.builder();
    for (AccumuloColumnHandle columnHandle : table.getColumns()) {
        if (columnHandle.getName().equalsIgnoreCase(source)) {
            newColumnList.add(new AccumuloColumnHandle(target, columnHandle.getFamily(), columnHandle.getQualifier(), columnHandle.getType(), columnHandle.getOrdinal(), columnHandle.getComment(), columnHandle.isIndexed()));
        } else {
            newColumnList.add(columnHandle);
        }
    }
    // Create new table metadata
    AccumuloTable newTable = new AccumuloTable(table.getSchema(), table.getTable(), newColumnList.build(), table.getRowId().equalsIgnoreCase(source) ? target : table.getRowId(), table.isExternal(), table.getSerializerClassName(), table.getScanAuthorizations());
    // Replace the table metadata
    metaManager.deleteTableMetadata(new SchemaTableName(table.getSchema(), table.getTable()));
    metaManager.createTableMetadata(newTable);
}
Also used : IndexLookup(com.facebook.presto.accumulo.index.IndexLookup) NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) Text(org.apache.hadoop.io.Text) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Pair(org.apache.commons.lang3.tuple.Pair) InvalidParameterException(java.security.InvalidParameterException) Locale(java.util.Locale) AccumuloSessionProperties(com.facebook.presto.accumulo.conf.AccumuloSessionProperties) AccumuloView(com.facebook.presto.accumulo.metadata.AccumuloView) Map(java.util.Map) Value(org.apache.accumulo.core.data.Value) Splitter(com.google.common.base.Splitter) FUNCTION_IMPLEMENTATION_ERROR(com.facebook.presto.spi.StandardErrorCode.FUNCTION_IMPLEMENTATION_ERROR) INVALID_TABLE_PROPERTY(com.facebook.presto.spi.StandardErrorCode.INVALID_TABLE_PROPERTY) AccumuloTableProperties(com.facebook.presto.accumulo.conf.AccumuloTableProperties) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ZooKeeperMetadataManager(com.facebook.presto.accumulo.metadata.ZooKeeperMetadataManager) Set(java.util.Set) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) TabletSplitMetadata(com.facebook.presto.accumulo.model.TabletSplitMetadata) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ConnectorSession(com.facebook.presto.spi.ConnectorSession) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) AccumuloConfig(com.facebook.presto.accumulo.conf.AccumuloConfig) Entry(java.util.Map.Entry) Optional(java.util.Optional) Scanner(org.apache.accumulo.core.client.Scanner) Iterables(com.google.common.collect.Iterables) Logger(com.facebook.airlift.log.Logger) AccumuloRowSerializer(com.facebook.presto.accumulo.serializers.AccumuloRowSerializer) HashMap(java.util.HashMap) PrestoException(com.facebook.presto.spi.PrestoException) Indexer(com.facebook.presto.accumulo.index.Indexer) Connector(org.apache.accumulo.core.client.Connector) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) ALREADY_EXISTS(com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Key(org.apache.accumulo.core.data.Key) Objects.requireNonNull(java.util.Objects.requireNonNull) ACCUMULO_TABLE_EXISTS(com.facebook.presto.accumulo.AccumuloErrorCode.ACCUMULO_TABLE_EXISTS) ACCUMULO_TABLE_DNE(com.facebook.presto.accumulo.AccumuloErrorCode.ACCUMULO_TABLE_DNE) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Iterator(java.util.Iterator) AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) AccumuloPageSink(com.facebook.presto.accumulo.io.AccumuloPageSink) AccumuloColumnConstraint(com.facebook.presto.accumulo.model.AccumuloColumnConstraint) Authorizations(org.apache.accumulo.core.security.Authorizations) Domain(com.facebook.presto.common.predicate.Domain) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Range(org.apache.accumulo.core.data.Range) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) INVALID_VIEW(com.facebook.presto.spi.StandardErrorCode.INVALID_VIEW) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) PartialKey(org.apache.accumulo.core.data.PartialKey) UNEXPECTED_ACCUMULO_ERROR(com.facebook.presto.accumulo.AccumuloErrorCode.UNEXPECTED_ACCUMULO_ERROR) AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) ImmutableList(com.google.common.collect.ImmutableList) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 8 with AccumuloTable

use of com.facebook.presto.accumulo.metadata.AccumuloTable in project presto by prestodb.

the class AccumuloMetadata method renameColumn.

@Override
public void renameColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle source, String target) {
    AccumuloTableHandle handle = (AccumuloTableHandle) tableHandle;
    AccumuloColumnHandle columnHandle = (AccumuloColumnHandle) source;
    AccumuloTable table = client.getTable(handle.toSchemaTableName());
    if (table == null) {
        throw new TableNotFoundException(new SchemaTableName(handle.getSchema(), handle.getTable()));
    }
    client.renameColumn(table, columnHandle.getName(), target);
}
Also used : AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) AccumuloTableHandle(com.facebook.presto.accumulo.model.AccumuloTableHandle) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 9 with AccumuloTable

use of com.facebook.presto.accumulo.metadata.AccumuloTable in project presto by prestodb.

the class AccumuloMetadata method dropTable.

@Override
public void dropTable(ConnectorSession session, ConnectorTableHandle tableHandle) {
    AccumuloTableHandle handle = (AccumuloTableHandle) tableHandle;
    AccumuloTable table = client.getTable(handle.toSchemaTableName());
    if (table != null) {
        client.dropTable(table);
    }
}
Also used : AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) AccumuloTableHandle(com.facebook.presto.accumulo.model.AccumuloTableHandle)

Example 10 with AccumuloTable

use of com.facebook.presto.accumulo.metadata.AccumuloTable in project presto by prestodb.

the class AccumuloMetadata method getColumnHandles.

@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
    AccumuloTableHandle handle = (AccumuloTableHandle) tableHandle;
    checkArgument(handle.getConnectorId().equals(connectorId), "tableHandle is not for this connector");
    AccumuloTable table = client.getTable(handle.toSchemaTableName());
    if (table == null) {
        throw new TableNotFoundException(handle.toSchemaTableName());
    }
    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    for (AccumuloColumnHandle column : table.getColumns()) {
        columnHandles.put(column.getName(), column);
    }
    return columnHandles.build();
}
Also used : AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) AccumuloTableHandle(com.facebook.presto.accumulo.model.AccumuloTableHandle) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

AccumuloTable (com.facebook.presto.accumulo.metadata.AccumuloTable)10 AccumuloColumnHandle (com.facebook.presto.accumulo.model.AccumuloColumnHandle)5 SchemaTableName (com.facebook.presto.spi.SchemaTableName)5 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)5 AccumuloTableHandle (com.facebook.presto.accumulo.model.AccumuloTableHandle)4 AccumuloTableProperties (com.facebook.presto.accumulo.conf.AccumuloTableProperties)2 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)2 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)2 PrestoException (com.facebook.presto.spi.PrestoException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Logger (com.facebook.airlift.log.Logger)1 ACCUMULO_TABLE_DNE (com.facebook.presto.accumulo.AccumuloErrorCode.ACCUMULO_TABLE_DNE)1 ACCUMULO_TABLE_EXISTS (com.facebook.presto.accumulo.AccumuloErrorCode.ACCUMULO_TABLE_EXISTS)1 UNEXPECTED_ACCUMULO_ERROR (com.facebook.presto.accumulo.AccumuloErrorCode.UNEXPECTED_ACCUMULO_ERROR)1 AccumuloConfig (com.facebook.presto.accumulo.conf.AccumuloConfig)1 AccumuloSessionProperties (com.facebook.presto.accumulo.conf.AccumuloSessionProperties)1 IndexLookup (com.facebook.presto.accumulo.index.IndexLookup)1 Indexer (com.facebook.presto.accumulo.index.Indexer)1 AccumuloPageSink (com.facebook.presto.accumulo.io.AccumuloPageSink)1 AccumuloView (com.facebook.presto.accumulo.metadata.AccumuloView)1