Search in sources :

Example 16 with ByteArrayByteIterator

use of com.yahoo.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.

the class AccumuloClient method scan.

@Override
public Status scan(String t, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    try {
        checkTable(t);
    } catch (TableNotFoundException e) {
        System.err.println("Error trying to connect to Accumulo table." + e);
        return Status.ERROR;
    }
    // There doesn't appear to be a way to create a range for a given
    // LENGTH. Just start and end keys. So we'll do this the hard way for
    // now:
    // Just make the end 'infinity' and only read as much as we need.
    scanScanner.clearColumns();
    scanScanner.setRange(new Range(new Text(startkey), null));
    // If no fields are provided, we assume one column/row.
    if (fields != null) {
        // And add each of them as fields we want.
        for (String field : fields) {
            scanScanner.fetchColumn(colFam, new Text(field));
        }
    }
    String rowKey = "";
    HashMap<String, ByteIterator> currentHM = null;
    int count = 0;
    // Begin the iteration.
    for (Entry<Key, Value> entry : scanScanner) {
        // Check for a new row.
        if (!rowKey.equals(entry.getKey().getRow().toString())) {
            if (count++ == recordcount) {
                // Done reading the last row.
                break;
            }
            rowKey = entry.getKey().getRow().toString();
            if (fields != null) {
                // Initial Capacity for all keys.
                currentHM = new HashMap<String, ByteIterator>(fields.size());
            } else {
                // An empty result map.
                currentHM = new HashMap<String, ByteIterator>();
            }
            result.add(currentHM);
        }
        // Now add the key to the hashmap.
        Value v = entry.getValue();
        byte[] buf = v.get();
        currentHM.put(entry.getKey().getColumnQualifier().toString(), new ByteArrayByteIterator(buf));
    }
    return Status.OK;
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key)

Example 17 with ByteArrayByteIterator

use of com.yahoo.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.

the class AccumuloClient method read.

@Override
public Status read(String t, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    try {
        checkTable(t);
    } catch (TableNotFoundException e) {
        System.err.println("Error trying to connect to Accumulo table." + e);
        return Status.ERROR;
    }
    try {
        // Pick out the results we care about.
        for (Entry<Key, Value> entry : getRow(new Text(key), null)) {
            Value v = entry.getValue();
            byte[] buf = v.get();
            result.put(entry.getKey().getColumnQualifier().toString(), new ByteArrayByteIterator(buf));
        }
    } catch (Exception e) {
        System.err.println("Error trying to reading Accumulo table" + key + e);
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) Key(org.apache.accumulo.core.data.Key) DBException(com.yahoo.ycsb.DBException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 18 with ByteArrayByteIterator

use of com.yahoo.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.

the class AsyncHBaseClient method scan.

@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    setTable(table);
    final Scanner scanner = client.newScanner(lastTableBytes);
    scanner.setFamily(columnFamilyBytes);
    scanner.setStartKey(startkey.getBytes(UTF8_CHARSET));
    // No end key... *sniff*
    if (fields != null) {
        scanner.setQualifiers(getQualifierList(fields));
    }
    // no filters? *sniff*
    ArrayList<ArrayList<KeyValue>> rows = null;
    try {
        int numResults = 0;
        while ((rows = scanner.nextRows().join(joinTimeout)) != null) {
            for (final ArrayList<KeyValue> row : rows) {
                final HashMap<String, ByteIterator> rowResult = new HashMap<String, ByteIterator>(row.size());
                for (final KeyValue column : row) {
                    rowResult.put(new String(column.qualifier()), // be GC'd.
                    new ByteArrayByteIterator(column.value()));
                    if (debug) {
                        System.out.println("Got scan result for key: " + Bytes.pretty(column.key()));
                    }
                }
                result.add(rowResult);
                numResults++;
                if (numResults >= recordcount) {
                    // if hit recordcount, bail out
                    break;
                }
            }
        }
        scanner.close().join(joinTimeout);
        return Status.OK;
    } catch (InterruptedException e) {
        System.err.println("Thread interrupted");
        Thread.currentThread().interrupt();
    } catch (Exception e) {
        System.err.println("Failure reading from row with key " + startkey + ": " + e.getMessage());
        return Status.ERROR;
    }
    return Status.ERROR;
}
Also used : Scanner(org.hbase.async.Scanner) KeyValue(org.hbase.async.KeyValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DBException(com.yahoo.ycsb.DBException) IOException(java.io.IOException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator)

Example 19 with ByteArrayByteIterator

use of com.yahoo.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.

the class RiakUtils method deserializeTable.

/**
   * Deserializes an input byte array, transforming it into a list of (String, ByteIterator) pairs (i.e. a Map).
   *
   * @param aValue    A byte array containing the table to deserialize.
   * @param theResult A Map containing the deserialized table.
     */
private static void deserializeTable(final byte[] aValue, final Map<String, ByteIterator> theResult) {
    final ByteArrayInputStream anInputStream = new ByteArrayInputStream(aValue);
    byte[] aSizeBuffer = new byte[4];
    try {
        while (anInputStream.available() > 0) {
            anInputStream.read(aSizeBuffer);
            final int aColumnNameLength = fromBytes(aSizeBuffer);
            final byte[] aColumnNameBuffer = new byte[aColumnNameLength];
            anInputStream.read(aColumnNameBuffer);
            anInputStream.read(aSizeBuffer);
            final int aColumnValueLength = fromBytes(aSizeBuffer);
            final byte[] aColumnValue = new byte[aColumnValueLength];
            anInputStream.read(aColumnValue);
            theResult.put(new String(aColumnNameBuffer), new ByteArrayByteIterator(aColumnValue));
        }
    } catch (Exception e) {
        throw new IllegalStateException(e);
    } finally {
        close(anInputStream);
    }
}
Also used : ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator)

Example 20 with ByteArrayByteIterator

use of com.yahoo.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.

the class HypertableClient method scan.

/**
   * Perform a range scan for a set of records in the database. Each field/value
   * pair from the result will be stored in a HashMap.
   *
   * @param table
   *          The name of the table
   * @param startkey
   *          The record key of the first record to read.
   * @param recordcount
   *          The number of records to read
   * @param fields
   *          The list of fields to read, or null for all of them
   * @param result
   *          A Vector of HashMaps, where each HashMap is a set field/value
   *          pairs for one record
   * @return Zero on success, a non-zero error code on error
   */
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    // SELECT _columnFamily:fields FROM table WHERE (ROW >= startkey)
    // LIMIT recordcount MAX_VERSIONS 1;
    ScanSpec spec = new ScanSpec();
    RowInterval elem = new RowInterval();
    elem.setStart_inclusive(true);
    elem.setStart_row(startkey);
    spec.addToRow_intervals(elem);
    if (null != fields) {
        for (String field : fields) {
            spec.addToColumns(columnFamily + ":" + field);
        }
    }
    spec.setVersions(1);
    spec.setRow_limit(recordcount);
    SerializedCellsReader reader = new SerializedCellsReader(null);
    try {
        long sc = connection.scanner_open(ns, table, spec);
        String lastRow = null;
        boolean eos = false;
        while (!eos) {
            reader.reset(connection.scanner_get_cells_serialized(sc));
            while (reader.next()) {
                String currentRow = new String(reader.get_row());
                if (!currentRow.equals(lastRow)) {
                    result.add(new HashMap<String, ByteIterator>());
                    lastRow = currentRow;
                }
                result.lastElement().put(new String(reader.get_column_qualifier()), new ByteArrayByteIterator(reader.get_value()));
            }
            eos = reader.eos();
            if (debug) {
                System.out.println("Number of rows retrieved so far: " + result.size());
            }
        }
        connection.scanner_close(sc);
    } catch (ClientException e) {
        if (debug) {
            System.err.println("Error doing scan: " + e.message);
        }
        return Status.ERROR;
    } catch (TException e) {
        if (debug) {
            System.err.println("Error doing scan");
        }
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : TException(org.apache.thrift.TException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) ClientException(org.hypertable.thriftgen.ClientException) RowInterval(org.hypertable.thriftgen.RowInterval) SerializedCellsReader(org.hypertable.thrift.SerializedCellsReader) ScanSpec(org.hypertable.thriftgen.ScanSpec)

Aggregations

ByteArrayByteIterator (com.yahoo.ycsb.ByteArrayByteIterator)25 ByteIterator (com.yahoo.ycsb.ByteIterator)15 HashMap (java.util.HashMap)12 DBException (com.yahoo.ycsb.DBException)9 IOException (java.io.IOException)6 DB (com.yahoo.ycsb.DB)4 Status (com.yahoo.ycsb.Status)4 EntityProperty (com.microsoft.azure.storage.table.EntityProperty)3 Test (org.junit.Test)3 ColumnDefinitions (com.datastax.driver.core.ColumnDefinitions)2 ResultSet (com.datastax.driver.core.ResultSet)2 Row (com.datastax.driver.core.Row)2 SimpleStatement (com.datastax.driver.core.SimpleStatement)2 Statement (com.datastax.driver.core.Statement)2 Select (com.datastax.driver.core.querybuilder.Select)2 ByteString (com.google.bigtable.repackaged.com.google.protobuf.ByteString)2 Column (com.google.bigtable.v1.Column)2 Family (com.google.bigtable.v1.Family)2 DeleteFromRow (com.google.bigtable.v1.Mutation.DeleteFromRow)2 ReadRowsRequest (com.google.bigtable.v1.ReadRowsRequest)2