Search in sources :

Example 1 with DocumentStore

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;
    }
}
Also used : DocumentStore(org.ojai.store.DocumentStore) Document(org.ojai.Document)

Example 2 with DocumentStore

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;
    }
}
Also used : DocumentStore(org.ojai.store.DocumentStore)

Example 3 with DocumentStore

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;
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) FloatValue(graphql.language.FloatValue) Value(graphql.language.Value) ValuesResolver(graphql.execution.ValuesResolver) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) DocumentStore(org.ojai.store.DocumentStore) LoggerFactory(org.slf4j.LoggerFactory) ConditionNode(io.hdocdb.store.ConditionNode) LIMIT_PARAM_NAME(io.kgraph.kgiraffe.schema.GraphQLSchemaBuilder.LIMIT_PARAM_NAME) InputValueWithState(graphql.schema.InputValueWithState) Map(java.util.Map) Document(org.ojai.Document) GraphQLException(graphql.GraphQLException) TypeMetaFieldDef(graphql.introspection.Introspection.TypeMetaFieldDef) ConditionLeaf(io.hdocdb.store.ConditionLeaf) DataFetchingEnvironmentBuilder(io.kgraph.kgiraffe.schema.util.DataFetchingEnvironmentBuilder) Collection(java.util.Collection) ObjectField(graphql.language.ObjectField) GraphQLArgument(graphql.schema.GraphQLArgument) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) ArrayValue(graphql.language.ArrayValue) Optional(java.util.Optional) GraphQLSupport(io.kgraph.kgiraffe.schema.util.GraphQLSupport) NullValue(graphql.language.NullValue) ObjectValue(graphql.language.ObjectValue) IntStream(java.util.stream.IntStream) Iterables(com.google.common.collect.Iterables) HQueryCondition(io.hdocdb.store.HQueryCondition) EnumValue(graphql.language.EnumValue) GraphQLType(graphql.schema.GraphQLType) Streams(io.kcache.utils.Streams) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ORDER_BY_PARAM_NAME(io.kgraph.kgiraffe.schema.GraphQLSchemaBuilder.ORDER_BY_PARAM_NAME) VariableReference(graphql.language.VariableReference) GraphQLSchema(graphql.schema.GraphQLSchema) ConditionParent(io.hdocdb.store.ConditionParent) SimpleEntry(java.util.AbstractMap.SimpleEntry) TypeNameMetaFieldDef(graphql.introspection.Introspection.TypeNameMetaFieldDef) OFFSET_PARAM_NAME(io.kgraph.kgiraffe.schema.GraphQLSchemaBuilder.OFFSET_PARAM_NAME) Criteria(io.kgraph.kgiraffe.schema.PredicateFilter.Criteria) Logger(org.slf4j.Logger) KGiraffeEngine(io.kgraph.kgiraffe.KGiraffeEngine) FieldPath(org.ojai.FieldPath) GraphQLOutputType(graphql.schema.GraphQLOutputType) Field(graphql.language.Field) GraphQLImplementingType(graphql.schema.GraphQLImplementingType) QueryCondition(org.ojai.store.QueryCondition) Argument(graphql.language.Argument) GraphQLList(graphql.schema.GraphQLList) StringValue(graphql.language.StringValue) Tuple2(io.vavr.Tuple2) HValue(io.hdocdb.HValue) IntValue(graphql.language.IntValue) SchemaMetaFieldDef(graphql.introspection.Introspection.SchemaMetaFieldDef) Comparator(java.util.Comparator) GraphQLFieldsContainer(graphql.schema.GraphQLFieldsContainer) Collections(java.util.Collections) BooleanValue(graphql.language.BooleanValue) GraphQLArgument(graphql.schema.GraphQLArgument) Argument(graphql.language.Argument) FieldPath(org.ojai.FieldPath) Document(org.ojai.Document) HValue(io.hdocdb.HValue) DocumentStore(org.ojai.store.DocumentStore) HQueryCondition(io.hdocdb.store.HQueryCondition) QueryCondition(org.ojai.store.QueryCondition) IntValue(graphql.language.IntValue)

Example 4 with DocumentStore

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;
    }
}
Also used : DocumentStore(org.ojai.store.DocumentStore)

Example 5 with DocumentStore

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;
    }
}
Also used : DocumentStore(org.ojai.store.DocumentStore)

Aggregations

DocumentStore (org.ojai.store.DocumentStore)6 Document (org.ojai.Document)3 Iterables (com.google.common.collect.Iterables)1 GraphQLException (graphql.GraphQLException)1 ValuesResolver (graphql.execution.ValuesResolver)1 SchemaMetaFieldDef (graphql.introspection.Introspection.SchemaMetaFieldDef)1 TypeMetaFieldDef (graphql.introspection.Introspection.TypeMetaFieldDef)1 TypeNameMetaFieldDef (graphql.introspection.Introspection.TypeNameMetaFieldDef)1 Argument (graphql.language.Argument)1 ArrayValue (graphql.language.ArrayValue)1 BooleanValue (graphql.language.BooleanValue)1 EnumValue (graphql.language.EnumValue)1 Field (graphql.language.Field)1 FloatValue (graphql.language.FloatValue)1 IntValue (graphql.language.IntValue)1 NullValue (graphql.language.NullValue)1 ObjectField (graphql.language.ObjectField)1 ObjectValue (graphql.language.ObjectValue)1 StringValue (graphql.language.StringValue)1 Value (graphql.language.Value)1