Search in sources :

Example 11 with Value

use of org.apache.accumulo.core.data.Value in project hive by apache.

the class HiveAccumuloRecordReader method pushToValue.

// flatten key/value pairs into row object for use in Serde.
private void pushToValue(List<Key> keys, List<Value> values, AccumuloHiveRow row) throws IOException {
    Iterator<Key> kIter = keys.iterator();
    Iterator<Value> vIter = values.iterator();
    while (kIter.hasNext()) {
        Key k = kIter.next();
        Value v = vIter.next();
        row.add(k.getColumnFamily().toString(), k.getColumnQualifier().toString(), v.get());
    }
}
Also used : Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Example 12 with Value

use of org.apache.accumulo.core.data.Value in project presto by prestodb.

the class IndexLookup method getIndexRanges.

private List<Range> getIndexRanges(String indexTable, Multimap<AccumuloColumnConstraint, Range> constraintRanges, Collection<Range> rowIDRanges, Authorizations auths) throws TableNotFoundException {
    Set<Range> finalRanges = null;
    // For each column/constraint pair
    for (Entry<AccumuloColumnConstraint, Collection<Range>> constraintEntry : constraintRanges.asMap().entrySet()) {
        // Create a batch scanner against the index table, setting the ranges
        BatchScanner scanner = connector.createBatchScanner(indexTable, auths, 10);
        scanner.setRanges(constraintEntry.getValue());
        // Fetch the column family for this specific column
        Text family = new Text(Indexer.getIndexColumnFamily(constraintEntry.getKey().getFamily().getBytes(UTF_8), constraintEntry.getKey().getQualifier().getBytes(UTF_8)).array());
        scanner.fetchColumnFamily(family);
        // For each entry in the scanner
        Text tmpQualifier = new Text();
        Set<Range> columnRanges = new HashSet<>();
        for (Entry<Key, Value> entry : scanner) {
            entry.getKey().getColumnQualifier(tmpQualifier);
            // Add to our column ranges if it is in one of the row ID ranges
            if (inRange(tmpQualifier, rowIDRanges)) {
                columnRanges.add(new Range(tmpQualifier));
            }
        }
        LOG.debug("Retrieved %d ranges for column %s", columnRanges.size(), constraintEntry.getKey().getName());
        // If finalRanges is null, we have not yet added any column ranges
        if (finalRanges == null) {
            finalRanges = new HashSet<>();
            finalRanges.addAll(columnRanges);
        } else {
            // Retain only the row IDs for this column that have already been added
            // This is your set intersection operation!
            finalRanges.retainAll(columnRanges);
        }
        // Close the scanner
        scanner.close();
    }
    // Return the final ranges for all constraint pairs
    if (finalRanges != null) {
        return ImmutableList.copyOf(finalRanges);
    } else {
        return ImmutableList.of();
    }
}
Also used : AccumuloColumnConstraint(com.facebook.presto.accumulo.model.AccumuloColumnConstraint) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Value(org.apache.accumulo.core.data.Value) Collection(java.util.Collection) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet)

Example 13 with Value

use of org.apache.accumulo.core.data.Value in project presto by prestodb.

the class IndexLookup method getNumRowsInTable.

private long getNumRowsInTable(String metricsTable, Authorizations auths) throws TableNotFoundException {
    // Create scanner against the metrics table, pulling the special column and the rows column
    Scanner scanner = connector.createScanner(metricsTable, auths);
    scanner.setRange(METRICS_TABLE_ROWID_RANGE);
    scanner.fetchColumn(Indexer.METRICS_TABLE_ROWS_CF_AS_TEXT, Indexer.CARDINALITY_CQ_AS_TEXT);
    // Scan the entry and get the number of rows
    long numRows = -1;
    for (Entry<Key, Value> entry : scanner) {
        if (numRows > 0) {
            throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, "Should have received only one entry when scanning for number of rows in metrics table");
        }
        numRows = Long.parseLong(entry.getValue().toString());
    }
    scanner.close();
    LOG.debug("Number of rows in table is %d", numRows);
    return numRows;
}
Also used : BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) Value(org.apache.accumulo.core.data.Value) PrestoException(com.facebook.presto.spi.PrestoException) Key(org.apache.accumulo.core.data.Key)

Example 14 with Value

use of org.apache.accumulo.core.data.Value in project presto by prestodb.

the class AbstractTestAccumuloRowSerializer method deserializeData.

protected void deserializeData(AccumuloRowSerializer serializer, byte[] data) throws Exception {
    Mutation m = new Mutation("row");
    m.put(b("a"), b("a"), data);
    Key key = new Key(b("row"), b("a"), b("b"), b(), 0, false);
    Value value = new Value(data);
    serializer.setMapping(COLUMN_NAME, "a", "b");
    serializer.deserialize(new SimpleImmutableEntry<>(key, value));
}
Also used : Value(org.apache.accumulo.core.data.Value) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key)

Example 15 with Value

use of org.apache.accumulo.core.data.Value in project YCSB by brianfrankcooper.

the class AccumuloClient method deleteRow.

/**
   * Deletes a row, given a Scanner of JUST that row.
   */
private void deleteRow(Scanner scanner) throws MutationsRejectedException {
    Mutation deleter = null;
    // iterate through the keys
    for (Entry<Key, Value> entry : scanner) {
        // create a mutation for the row
        if (deleter == null) {
            deleter = new Mutation(entry.getKey().getRow());
        }
        // the remove function adds the key with the delete flag set to true
        deleter.putDelete(entry.getKey().getColumnFamily(), entry.getKey().getColumnQualifier());
    }
    bw.addMutation(deleter);
}
Also used : Value(org.apache.accumulo.core.data.Value) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key)

Aggregations

Value (org.apache.accumulo.core.data.Value)79 Key (org.apache.accumulo.core.data.Key)64 Test (org.junit.Test)38 Edge (uk.gov.gchq.gaffer.data.element.Edge)30 HashMap (java.util.HashMap)23 Element (uk.gov.gchq.gaffer.data.element.Element)23 Mutation (org.apache.accumulo.core.data.Mutation)21 Text (org.apache.hadoop.io.Text)21 Authorizations (org.apache.accumulo.core.security.Authorizations)18 Entry (java.util.Map.Entry)15 Scanner (org.apache.accumulo.core.client.Scanner)15 BatchWriter (org.apache.accumulo.core.client.BatchWriter)12 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)11 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)11 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)11 AccumuloException (org.apache.accumulo.core.client.AccumuloException)10 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)10 Connector (org.apache.accumulo.core.client.Connector)9 Properties (uk.gov.gchq.gaffer.data.element.Properties)9 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)8