use of com.facebook.presto.accumulo.model.AccumuloColumnHandle in project presto by prestodb.
the class AccumuloPageSink method toMutation.
/**
* Converts a {@link Row} to an Accumulo mutation.
*
* @param row Row object
* @param rowIdOrdinal Ordinal in the list of columns that is the row ID. This isn't checked at all, so I hope you're right. Also, it is expected that the list of column handles is sorted in ordinal order. This is a very demanding function.
* @param columns All column handles for the Row, sorted by ordinal.
* @param serializer Instance of {@link AccumuloRowSerializer} used to encode the values of the row to the Mutation
* @return Mutation
*/
public static Mutation toMutation(Row row, int rowIdOrdinal, List<AccumuloColumnHandle> columns, AccumuloRowSerializer serializer) {
// Set our value to the row ID
Text value = new Text();
Field rowField = row.getField(rowIdOrdinal);
if (rowField.isNull()) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Column mapped as the Accumulo row ID cannot be null");
}
setText(rowField, value, serializer);
// Iterate through all the column handles, setting the Mutation's columns
Mutation mutation = new Mutation(value);
// Store row ID in a special column
mutation.put(ROW_ID_COLUMN, ROW_ID_COLUMN, new Value(value.copyBytes()));
for (AccumuloColumnHandle columnHandle : columns) {
// Skip the row ID ordinal
if (columnHandle.getOrdinal() == rowIdOrdinal) {
continue;
}
// If the value of the field is not null
if (!row.getField(columnHandle.getOrdinal()).isNull()) {
// Serialize the value to the text
setText(row.getField(columnHandle.getOrdinal()), value, serializer);
// And add the bytes to the Mutation
mutation.put(columnHandle.getFamily().get(), columnHandle.getQualifier().get(), new Value(value.copyBytes()));
}
}
return mutation;
}
use of com.facebook.presto.accumulo.model.AccumuloColumnHandle 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.model.AccumuloColumnHandle in project presto by prestodb.
the class AccumuloClient method setLocalityGroups.
private void setLocalityGroups(Map<String, Object> tableProperties, AccumuloTable table) {
Optional<Map<String, Set<String>>> groups = AccumuloTableProperties.getLocalityGroups(tableProperties);
if (!groups.isPresent()) {
LOG.debug("No locality groups to set");
return;
}
ImmutableMap.Builder<String, Set<Text>> localityGroupsBuilder = ImmutableMap.builder();
for (Map.Entry<String, Set<String>> g : groups.get().entrySet()) {
ImmutableSet.Builder<Text> familyBuilder = ImmutableSet.builder();
// For each configured column for this locality group
for (String col : g.getValue()) {
// Locate the column family mapping via the Handle
// We already validated this earlier, so it'll exist
AccumuloColumnHandle handle = table.getColumns().stream().filter(x -> x.getName().equals(col)).collect(Collectors.toList()).get(0);
familyBuilder.add(new Text(handle.getFamily().get()));
}
localityGroupsBuilder.put(g.getKey(), familyBuilder.build());
}
Map<String, Set<Text>> localityGroups = localityGroupsBuilder.build();
LOG.debug("Setting locality groups: {}", localityGroups);
tableManager.setLocalityGroups(table.getFullTableName(), localityGroups);
}
use of com.facebook.presto.accumulo.model.AccumuloColumnHandle 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.model.AccumuloColumnHandle 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