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);
}
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);
}
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);
}
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);
}
}
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();
}
Aggregations