Search in sources :

Example 1 with AccumuloColumnHandle

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();
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ImmutableList(com.google.common.collect.ImmutableList) AccumuloColumnConstraint(com.facebook.presto.accumulo.model.AccumuloColumnConstraint) InvalidParameterException(java.security.InvalidParameterException) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with AccumuloColumnHandle

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;
}
Also used : AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle)

Example 3 with AccumuloColumnHandle

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;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashMap(java.util.HashMap) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) Text(org.apache.hadoop.io.Text)

Example 4 with AccumuloColumnHandle

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);
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with AccumuloColumnHandle

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());
}
Also used : AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) AccumuloSplit(com.facebook.presto.accumulo.model.AccumuloSplit)

Aggregations

AccumuloColumnHandle (com.facebook.presto.accumulo.model.AccumuloColumnHandle)10 AccumuloTable (com.facebook.presto.accumulo.metadata.AccumuloTable)5 Text (org.apache.hadoop.io.Text)4 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 AccumuloColumnConstraint (com.facebook.presto.accumulo.model.AccumuloColumnConstraint)2 AccumuloTableHandle (com.facebook.presto.accumulo.model.AccumuloTableHandle)2 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)2 PrestoException (com.facebook.presto.spi.PrestoException)2 SchemaTableName (com.facebook.presto.spi.SchemaTableName)2 ImmutableList (com.google.common.collect.ImmutableList)2 Map (java.util.Map)2 Value (org.apache.accumulo.core.data.Value)2 MoreFutures.getFutureValue (com.facebook.airlift.concurrent.MoreFutures.getFutureValue)1 Logger (com.facebook.airlift.log.Logger)1 ACCUMULO_TABLE_DNE (com.facebook.presto.accumulo.AccumuloErrorCode.ACCUMULO_TABLE_DNE)1