use of com.facebook.presto.accumulo.model.AccumuloColumnHandle in project presto by prestodb.
the class AccumuloClient method getColumnHandles.
private static List<AccumuloColumnHandle> getColumnHandles(ConnectorTableMetadata meta, String rowIdColumn) {
// Get the column mappings from the table property or auto-generate columns if not defined
Map<String, Pair<String, String>> mapping = AccumuloTableProperties.getColumnMapping(meta.getProperties()).orElse(autoGenerateMapping(meta.getColumns(), AccumuloTableProperties.getLocalityGroups(meta.getProperties())));
// The list of indexed columns
Optional<List<String>> indexedColumns = AccumuloTableProperties.getIndexColumns(meta.getProperties());
// And now we parse the configured columns and create handles for the metadata manager
ImmutableList.Builder<AccumuloColumnHandle> cBuilder = ImmutableList.builder();
for (int ordinal = 0; ordinal < meta.getColumns().size(); ++ordinal) {
ColumnMetadata cm = meta.getColumns().get(ordinal);
// Special case if this column is the row ID
if (cm.getName().equalsIgnoreCase(rowIdColumn)) {
cBuilder.add(new AccumuloColumnHandle(rowIdColumn, Optional.empty(), Optional.empty(), cm.getType(), ordinal, "Accumulo row ID", false));
} else {
if (!mapping.containsKey(cm.getName())) {
throw new InvalidParameterException(format("Misconfigured mapping for presto column %s", cm.getName()));
}
// Get the mapping for this column
Pair<String, String> famqual = mapping.get(cm.getName());
boolean indexed = indexedColumns.isPresent() && indexedColumns.get().contains(cm.getName().toLowerCase(Locale.ENGLISH));
String comment = format("Accumulo column %s:%s. Indexed: %b", famqual.getLeft(), famqual.getRight(), indexed);
// Create a new AccumuloColumnHandle object
cBuilder.add(new AccumuloColumnHandle(cm.getName(), Optional.of(famqual.getLeft()), Optional.of(famqual.getRight()), cm.getType(), ordinal, comment, indexed));
}
}
return cBuilder.build();
}
use of com.facebook.presto.accumulo.model.AccumuloColumnHandle in project presto by prestodb.
the class AccumuloClient method createTable.
public AccumuloTable createTable(ConnectorTableMetadata meta) {
// Validate the DDL is something we can handle
validateCreateTable(meta);
Map<String, Object> tableProperties = meta.getProperties();
String rowIdColumn = getRowIdColumn(meta);
// Get the list of column handles
List<AccumuloColumnHandle> columns = getColumnHandles(meta, rowIdColumn);
// Create the AccumuloTable object
AccumuloTable table = new AccumuloTable(meta.getTable().getSchemaName(), meta.getTable().getTableName(), columns, rowIdColumn, AccumuloTableProperties.isExternal(tableProperties), AccumuloTableProperties.getSerializerClass(tableProperties), AccumuloTableProperties.getScanAuthorizations(tableProperties));
// First, create the metadata
metaManager.createTableMetadata(table);
// Make sure the namespace exists
tableManager.ensureNamespace(table.getSchema());
// Create the Accumulo table if it does not exist (for 'external' table)
if (!tableManager.exists(table.getFullTableName())) {
tableManager.createAccumuloTable(table.getFullTableName());
}
// Set any locality groups on the data table
setLocalityGroups(tableProperties, table);
// Create index tables, if appropriate
createIndexTables(table);
return table;
}
use of com.facebook.presto.accumulo.model.AccumuloColumnHandle in project presto by prestodb.
the class Indexer method getLocalityGroups.
/**
* Gets a set of locality groups that should be added to the index table (not the metrics table).
*
* @param table Table for the locality groups, see AccumuloClient#getTable
* @return Mapping of locality group to column families in the locality group, 1:1 mapping in
* this case
*/
public static Map<String, Set<Text>> getLocalityGroups(AccumuloTable table) {
Map<String, Set<Text>> groups = new HashMap<>();
// For each indexed column
for (AccumuloColumnHandle columnHandle : table.getColumns().stream().filter(AccumuloColumnHandle::isIndexed).collect(Collectors.toList())) {
// Create a Text version of the index column family
Text indexColumnFamily = new Text(getIndexColumnFamily(columnHandle.getFamily().get().getBytes(UTF_8), columnHandle.getQualifier().get().getBytes(UTF_8)).array());
// Add this to the locality groups,
// it is a 1:1 mapping of locality group to column families
groups.put(indexColumnFamily.toString(), ImmutableSet.of(indexColumnFamily));
}
return groups;
}
use of com.facebook.presto.accumulo.model.AccumuloColumnHandle in project presto by prestodb.
the class TestIndexer method setupClass.
@BeforeClass
public void setupClass() {
AccumuloColumnHandle c1 = new AccumuloColumnHandle("id", Optional.empty(), Optional.empty(), VARCHAR, 0, "", false);
AccumuloColumnHandle c2 = new AccumuloColumnHandle("age", Optional.of("cf"), Optional.of("age"), BIGINT, 1, "", true);
AccumuloColumnHandle c3 = new AccumuloColumnHandle("firstname", Optional.of("cf"), Optional.of("firstname"), VARCHAR, 2, "", true);
AccumuloColumnHandle c4 = new AccumuloColumnHandle("arr", Optional.of("cf"), Optional.of("arr"), new ArrayType(VARCHAR), 3, "", true);
table = new AccumuloTable("default", "index_test_table", ImmutableList.of(c1, c2, c3, c4), "id", true, LexicoderRowSerializer.class.getCanonicalName(), null);
m1 = new Mutation(M1_ROWID);
m1.put(CF, AGE, AGE_VALUE);
m1.put(CF, FIRSTNAME, M1_FNAME_VALUE);
m1.put(CF, SENDERS, M1_ARR_VALUE);
m2 = new Mutation(M2_ROWID);
m2.put(CF, AGE, AGE_VALUE);
m2.put(CF, FIRSTNAME, M2_FNAME_VALUE);
m2.put(CF, SENDERS, M2_ARR_VALUE);
ColumnVisibility visibility1 = new ColumnVisibility("private");
ColumnVisibility visibility2 = new ColumnVisibility("moreprivate");
m1v = new Mutation(M1_ROWID);
m1v.put(CF, AGE, visibility1, AGE_VALUE);
m1v.put(CF, FIRSTNAME, visibility1, M1_FNAME_VALUE);
m1v.put(CF, SENDERS, visibility2, M1_ARR_VALUE);
m2v = new Mutation(M2_ROWID);
m2v.put(CF, AGE, visibility1, AGE_VALUE);
m2v.put(CF, FIRSTNAME, visibility2, M2_FNAME_VALUE);
m2v.put(CF, SENDERS, visibility2, M2_ARR_VALUE);
}
use of com.facebook.presto.accumulo.model.AccumuloColumnHandle in project presto by prestodb.
the class AccumuloRecordSetProvider method getRecordSet.
@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, List<? extends ColumnHandle> columns) {
requireNonNull(split, "split is null");
requireNonNull(columns, "columns is null");
// Convert split
AccumuloSplit accSplit = (AccumuloSplit) split;
checkArgument(accSplit.getConnectorId().equals(connectorId), "split is not for this connector");
// Convert all columns handles
ImmutableList.Builder<AccumuloColumnHandle> handles = ImmutableList.builder();
for (ColumnHandle handle : columns) {
handles.add((AccumuloColumnHandle) handle);
}
// Return new record set
return new AccumuloRecordSet(connector, session, accSplit, username, handles.build());
}
Aggregations