Search in sources :

Example 1 with SerializedCellsWriter

use of org.hypertable.thrift.SerializedCellsWriter in project YCSB by brianfrankcooper.

the class HypertableClient method insert.

/**
   * Insert a record in the database. Any field/value pairs in the specified
   * values HashMap will be written into the record with the specified record
   * key.
   *
   * @param table
   *          The name of the table
   * @param key
   *          The record key of the record to insert.
   * @param values
   *          A HashMap of field/value pairs to insert in the record
   * @return Zero on success, a non-zero error code on error
   */
@Override
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
    if (debug) {
        System.out.println("Setting up put for key: " + key);
    }
    try {
        long mutator = connection.mutator_open(ns, table, 0, 0);
        SerializedCellsWriter writer = new SerializedCellsWriter(BUFFER_SIZE * values.size(), true);
        for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
            writer.add(key, columnFamily, entry.getKey(), SerializedCellsFlag.AUTO_ASSIGN, ByteBuffer.wrap(entry.getValue().toArray()));
        }
        connection.mutator_set_cells_serialized(mutator, writer.buffer(), true);
        connection.mutator_close(mutator);
    } catch (ClientException e) {
        if (debug) {
            System.err.println("Error doing set: " + e.message);
        }
        return Status.ERROR;
    } catch (TException e) {
        if (debug) {
            System.err.println("Error doing set");
        }
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : SerializedCellsWriter(org.hypertable.thrift.SerializedCellsWriter) TException(org.apache.thrift.TException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) ClientException(org.hypertable.thriftgen.ClientException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ByteArrayByteIterator (com.yahoo.ycsb.ByteArrayByteIterator)1 ByteIterator (com.yahoo.ycsb.ByteIterator)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TException (org.apache.thrift.TException)1 SerializedCellsWriter (org.hypertable.thrift.SerializedCellsWriter)1 ClientException (org.hypertable.thriftgen.ClientException)1