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;
}
Aggregations