use of org.ojai.store.DocumentStore in project YCSB by brianfrankcooper.
the class MapRJSONDBClient method read.
@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
try {
DocumentStore docStore = getTable(table);
Document doc = docStore.findById(key, getFieldPaths(fields));
buildRowResult(doc, result);
return Status.OK;
} catch (Exception e) {
return Status.ERROR;
}
}
use of org.ojai.store.DocumentStore in project YCSB by brianfrankcooper.
the class MapRJSONDBClient method insert.
@Override
public Status insert(String table, String key, Map<String, ByteIterator> values) {
try {
DocumentStore docStore = getTable(table);
docStore.insertOrReplace(key, newDocument(values));
return Status.OK;
} catch (Exception e) {
return Status.ERROR;
}
}
use of org.ojai.store.DocumentStore in project kgiraffe by rayokota.
the class GraphQLQueryFactory method queryResult.
public Iterable<Document> queryResult(DataFetchingEnvironment env) {
QueryCondition query = getCriteriaQuery(env, env.getField());
DocumentStore coll = engine.getDocDB().getCollection(name);
Iterable<Document> result = query == null || query.isEmpty() ? coll.find() : coll.find(query);
// For debugging
// List<Document> docs = Streams.streamOf(coll.find()).collect(Collectors.toList());
// For debugging
Optional<Argument> offsetArg = getArgument(env.getField(), OFFSET_PARAM_NAME);
if (offsetArg.isPresent()) {
IntValue offsetValue = getValue(offsetArg.get(), env);
int offset = offsetValue.getValue().intValue();
result = Iterables.skip(result, offset);
}
Optional<Argument> limitArg = getArgument(env.getField(), LIMIT_PARAM_NAME);
if (limitArg.isPresent()) {
IntValue limitValue = getValue(limitArg.get(), env);
int limit = limitValue.getValue().intValue();
result = Iterables.limit(result, limit);
}
Tuple2<FieldPath, OrderBy> orderBy = getOrderBy(env, env.getField());
if (orderBy != null) {
Comparator<Document> cmp = orderBy._2 == OrderBy.ASC ? Comparator.comparing(doc -> (HValue) doc.getValue(orderBy._1), Comparator.nullsFirst(Comparator.naturalOrder())) : Comparator.comparing(doc -> (HValue) doc.getValue(orderBy._1), Comparator.nullsFirst(Comparator.reverseOrder()));
Stream<Document> stream = Streams.streamOf(result).sorted(cmp);
result = stream::iterator;
}
return result;
}
use of org.ojai.store.DocumentStore in project YCSB by brianfrankcooper.
the class MapRJSONDBClient method delete.
@Override
public Status delete(String table, String key) {
try {
DocumentStore docStore = getTable(table);
docStore.delete(key);
return Status.OK;
} catch (Exception e) {
return Status.ERROR;
}
}
use of org.ojai.store.DocumentStore in project YCSB by brianfrankcooper.
the class MapRJSONDBClient method update.
@Override
public Status update(String table, String key, Map<String, ByteIterator> values) {
try {
DocumentStore docStore = getTable(table);
docStore.update(key, newMutation(values));
return Status.OK;
} catch (Exception e) {
return Status.ERROR;
}
}
Aggregations