use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class HBaseClient1Test method testReadMissingRow.
@Test
public void testReadMissingRow() throws Exception {
final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
final Status status = client.read(tableName, "Missing row", null, result);
assertEquals(Status.NOT_FOUND, status);
assertEquals(0, result.size());
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class HBaseClient2 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) {
// if this is a "new" table, init HTable object. Else, use existing one
if (!tableName.equals(table)) {
currentTable = null;
try {
getHTable(table);
tableName = table;
} catch (IOException e) {
System.err.println("Error accessing HBase table: " + e);
return Status.ERROR;
}
}
Scan s = new Scan(Bytes.toBytes(startkey));
// HBase has no record limit. Here, assume recordcount is small enough to
// bring back in one call.
// We get back recordcount records
FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
s.setCaching(recordcount);
if (this.usePageFilter) {
filterList.addFilter(new PageFilter(recordcount));
}
// add specified fields or else all fields
if (fields == null) {
s.addFamily(columnFamilyBytes);
} else {
for (String field : fields) {
s.addColumn(columnFamilyBytes, Bytes.toBytes(field));
}
}
// define value filter if needed
if (useScanValueFiltering) {
filterList.addFilter(new ValueFilter(scanFilterOperator, scanFilterValue));
}
s.setFilter(filterList);
// get results
ResultScanner scanner = null;
try {
scanner = currentTable.getScanner(s);
int numResults = 0;
for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
// get row key
String key = Bytes.toString(rr.getRow());
if (debug) {
System.out.println("Got scan result for key: " + key);
}
HashMap<String, ByteIterator> rowResult = new HashMap<String, ByteIterator>();
while (rr.advance()) {
final Cell cell = rr.current();
rowResult.put(Bytes.toString(CellUtil.cloneQualifier(cell)), new ByteArrayByteIterator(CellUtil.cloneValue(cell)));
}
// add rowResult to result vector
result.add(rowResult);
numResults++;
// break is required.
if (numResults >= recordcount) {
// if hit recordcount, bail out
break;
}
}
// done with row
} catch (IOException e) {
if (debug) {
System.out.println("Error in getting/parsing scan result: " + e);
}
return Status.ERROR;
} finally {
if (scanner != null) {
scanner.close();
}
}
return Status.OK;
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class IgniteClientTest method testRead.
@Test
public void testRead() throws Exception {
cluster.cache(DEFAULT_CACHE_NAME).clear();
final String key = "key";
final Map<String, String> input = new HashMap<>();
input.put("field0", "value1");
input.put("field1", "value2A");
input.put("field3", null);
final Status sPut = client.insert(DEFAULT_CACHE_NAME, key, StringByteIterator.getByteIteratorMap(input));
assertThat(sPut, is(Status.OK));
assertThat(cluster.cache(DEFAULT_CACHE_NAME).size(), is(1));
final Set<String> fld = new TreeSet<>();
fld.add("field0");
fld.add("field1");
fld.add("field3");
final HashMap<String, ByteIterator> result = new HashMap<>();
final Status sGet = client.read(DEFAULT_CACHE_NAME, key, fld, result);
assertThat(sGet, is(Status.OK));
final HashMap<String, String> strResult = new HashMap<String, String>();
for (final Map.Entry<String, ByteIterator> e : result.entrySet()) {
if (e.getValue() != null) {
strResult.put(e.getKey(), e.getValue().toString());
}
}
assertThat(strResult, hasEntry("field0", "value1"));
assertThat(strResult, hasEntry("field1", "value2A"));
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class IgniteClientTest method testReadAllFields.
@Test
public void testReadAllFields() throws Exception {
cluster.cache(DEFAULT_CACHE_NAME).clear();
final String key = "key";
final Map<String, String> input = new HashMap<>();
input.put("field0", "value1");
input.put("field1", "value2A");
input.put("field3", null);
final Status sPut = client.insert(DEFAULT_CACHE_NAME, key, StringByteIterator.getByteIteratorMap(input));
assertThat(sPut, is(Status.OK));
assertThat(cluster.cache(DEFAULT_CACHE_NAME).size(), is(1));
final Set<String> fld = new TreeSet<>();
final HashMap<String, ByteIterator> result1 = new HashMap<>();
final Status sGet = client.read(DEFAULT_CACHE_NAME, key, fld, result1);
assertThat(sGet, is(Status.OK));
final HashMap<String, String> strResult = new HashMap<String, String>();
for (final Map.Entry<String, ByteIterator> e : result1.entrySet()) {
if (e.getValue() != null) {
strResult.put(e.getKey(), e.getValue().toString());
}
}
assertThat(strResult, hasEntry("field0", "value1"));
assertThat(strResult, hasEntry("field1", "value2A"));
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class GridDBClient method update.
public Status update(String table, String key, Map<String, ByteIterator> values) {
try {
Object rowKey = makeRowKey(key);
String containerKey = makeContainerKey(key);
final Container<Object, Row> container = store.getContainer(containerKey);
if (container == null) {
LOGGER.severe("[ERROR]getCollection " + containerKey + " in update()");
return Status.ERROR;
}
Row targetRow = container.get(rowKey);
if (targetRow == null) {
LOGGER.severe("[ERROR]get(rowKey) in update()");
return Status.ERROR;
}
int setCount = 0;
for (int i = 1; i < containerInfo.getColumnCount() && setCount < values.size(); i++) {
containerInfo.getColumnInfo(i).getName();
ByteIterator byteIterator = values.get(containerInfo.getColumnInfo(i).getName());
if (byteIterator != null) {
Object value = makeValue(byteIterator);
targetRow.setValue(i, value);
setCount++;
}
}
if (setCount != values.size()) {
LOGGER.severe("Error setCount = " + setCount);
return Status.ERROR;
}
container.put(targetRow);
return Status.OK;
} catch (GSException e) {
LOGGER.severe("Exception: " + e.getMessage());
return Status.ERROR;
}
}
Aggregations