use of com.arangodb.util.MapBuilder in project YCSB by brianfrankcooper.
the class ArangoDBClient 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. See the
* {@link DB} class's description for a discussion of error codes.
*/
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
DocumentCursor<BaseDocument> cursor = null;
try {
String aqlQuery = String.format("FOR target IN %s FILTER target._key >= @key SORT target._key ASC LIMIT %d RETURN %s ", table, recordcount, constructReturnForAQL(fields, "target"));
Map<String, Object> bindVars = new MapBuilder().put("key", startkey).get();
cursor = arangoDriver.executeDocumentQuery(aqlQuery, bindVars, null, BaseDocument.class);
Iterator<BaseDocument> iterator = cursor.entityIterator();
while (iterator.hasNext()) {
BaseDocument aDocument = iterator.next();
HashMap<String, ByteIterator> aMap = new HashMap<String, ByteIterator>(aDocument.getProperties().size());
if (!this.fillMap(aMap, aDocument.getProperties())) {
return Status.ERROR;
}
result.add(aMap);
}
return Status.OK;
} catch (Exception e) {
logger.error("Exception while trying scan {} {} {} with ex {}", table, startkey, recordcount, e.toString());
} finally {
if (cursor != null) {
try {
cursor.close();
} catch (ArangoException e) {
logger.error("Fail to close cursor", e);
}
}
}
return Status.ERROR;
}
use of com.arangodb.util.MapBuilder in project YCSB by brianfrankcooper.
the class ArangoDB3Client 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. See the
* {@link DB} class's description for a discussion of error codes.
*/
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
ArangoCursor<VPackSlice> cursor = null;
try {
String aqlQuery = String.format("FOR target IN %s FILTER target._key >= @key SORT target._key ASC LIMIT %d RETURN %s ", table, recordcount, constructReturnForAQL(fields, "target"));
Map<String, Object> bindVars = new MapBuilder().put("key", startkey).get();
cursor = arangoDB.db(databaseName).query(aqlQuery, bindVars, null, VPackSlice.class);
while (cursor.hasNext()) {
VPackSlice aDocument = cursor.next();
HashMap<String, ByteIterator> aMap = new HashMap<String, ByteIterator>(aDocument.size());
if (!this.fillMap(aMap, aDocument)) {
return Status.ERROR;
}
result.add(aMap);
}
return Status.OK;
} catch (Exception e) {
logger.error("Exception while trying scan {} {} {} with ex {}", table, startkey, recordcount, e.toString());
} finally {
if (cursor != null) {
try {
cursor.close();
} catch (IOException e) {
logger.error("Fail to close cursor", e);
}
}
}
return Status.ERROR;
}
Aggregations