Search in sources :

Example 1 with ParsedOp

use of io.nosqlbench.engine.api.templating.ParsedOp in project nosqlbench by nosqlbench.

the class DDBGetItemOpDispenser method resolveGetItemSpecFunction.

private LongFunction<GetItemSpec> resolveGetItemSpecFunction(ParsedOp cmd) {
    PrimaryKey primaryKey = null;
    LongFunction<PrimaryKey> pkfunc = null;
    String projection = null;
    LongFunction<String> projfunc = null;
    LongFunction<? extends Map> keysmap_func = cmd.getAsRequiredFunction("key", Map.class);
    LongFunction<PrimaryKey> pk_func = l -> {
        PrimaryKey pk = new PrimaryKey();
        keysmap_func.apply(l).forEach((k, v) -> {
            pk.addComponent(k.toString(), v);
        });
        return pk;
    };
    LongFunction<GetItemSpec> gis = l -> new GetItemSpec().withPrimaryKey(pk_func.apply(l));
    Optional<LongFunction<String>> projection_func = cmd.getAsOptionalFunction("projection", String.class);
    if (projection_func.isPresent()) {
        LongFunction<GetItemSpec> finalGis = gis;
        gis = l -> {
            LongFunction<String> pj = projection_func.get();
            return finalGis.apply(l).withProjectionExpression(pj.apply(1));
        };
    }
    Optional<LongFunction<Boolean>> consistentRead = cmd.getAsOptionalFunction("ConsistentRead", boolean.class);
    if (consistentRead.isPresent()) {
        LongFunction<GetItemSpec> finalGis = gis;
        gis = l -> {
            LongFunction<Boolean> consistentReadFunc = consistentRead.get();
            return finalGis.apply(l).withConsistentRead(consistentReadFunc.apply(l));
        };
    }
    return gis;
}
Also used : BaseOpDispenser(io.nosqlbench.engine.api.activityimpl.BaseOpDispenser) LongFunction(java.util.function.LongFunction) GetItemSpec(com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec) PrimaryKey(com.amazonaws.services.dynamodbv2.document.PrimaryKey) Map(java.util.Map) ParsedOp(io.nosqlbench.engine.api.templating.ParsedOp) Optional(java.util.Optional) Table(com.amazonaws.services.dynamodbv2.document.Table) DDBGetItemOp(io.nosqlbench.adapter.dynamodb.optypes.DDBGetItemOp) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) DynamoDBOp(io.nosqlbench.adapter.dynamodb.optypes.DynamoDBOp) PrimaryKey(com.amazonaws.services.dynamodbv2.document.PrimaryKey) LongFunction(java.util.function.LongFunction) GetItemSpec(com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec)

Example 2 with ParsedOp

use of io.nosqlbench.engine.api.templating.ParsedOp in project nosqlbench by nosqlbench.

the class DDBQueryOpDispenser method resolveQuerySpecFunc.

private LongFunction<QuerySpec> resolveQuerySpecFunc(ParsedOp cmd) {
    LongFunction<QuerySpec> func = l -> new QuerySpec();
    Optional<LongFunction<String>> projFunc = cmd.getAsOptionalFunction("projection", String.class);
    if (projFunc.isPresent()) {
        LongFunction<QuerySpec> finalFunc = func;
        LongFunction<String> af = projFunc.get();
        func = l -> finalFunc.apply(l).withAttributesToGet(af.apply(l));
    }
    Optional<LongFunction<Boolean>> consistentRead = cmd.getAsOptionalFunction("ConsistentRead", boolean.class);
    if (consistentRead.isPresent()) {
        LongFunction<QuerySpec> finalFunc = func;
        LongFunction<Boolean> consistentReadFunc = consistentRead.get();
        func = l -> finalFunc.apply(l).withConsistentRead(consistentReadFunc.apply(l));
    }
    Optional<LongFunction<Map>> exclStrtKeyFunc = cmd.getAsOptionalFunction("ExclusiveStartKey", Map.class);
    if (exclStrtKeyFunc.isPresent()) {
        LongFunction<QuerySpec> finalFunc = func;
        LongFunction<Map> skf = exclStrtKeyFunc.get();
        LongFunction<PrimaryKey> pkf = l -> {
            PrimaryKey pk = new PrimaryKey();
            skf.apply(l).forEach((k, v) -> pk.addComponent(k.toString(), v.toString()));
            return pk;
        };
        func = l -> finalFunc.apply(l).withExclusiveStartKey(pkf.apply(l));
    }
    Optional<LongFunction<Integer>> limitFunc = cmd.getAsOptionalFunction("Limit", Integer.class);
    if (limitFunc.isPresent()) {
        LongFunction<Integer> limitf = limitFunc.get();
        LongFunction<QuerySpec> finalFunc = func;
        func = l -> finalFunc.apply(l).withMaxResultSize(limitf.apply(l));
    }
    return func;
}
Also used : BaseOpDispenser(io.nosqlbench.engine.api.activityimpl.BaseOpDispenser) LongFunction(java.util.function.LongFunction) PrimaryKey(com.amazonaws.services.dynamodbv2.document.PrimaryKey) Map(java.util.Map) ParsedOp(io.nosqlbench.engine.api.templating.ParsedOp) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) Optional(java.util.Optional) Table(com.amazonaws.services.dynamodbv2.document.Table) DDBQueryOp(io.nosqlbench.adapter.dynamodb.optypes.DDBQueryOp) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) DynamoDBOp(io.nosqlbench.adapter.dynamodb.optypes.DynamoDBOp) PrimaryKey(com.amazonaws.services.dynamodbv2.document.PrimaryKey) LongFunction(java.util.function.LongFunction) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) Map(java.util.Map)

Aggregations

DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)2 PrimaryKey (com.amazonaws.services.dynamodbv2.document.PrimaryKey)2 Table (com.amazonaws.services.dynamodbv2.document.Table)2 DynamoDBOp (io.nosqlbench.adapter.dynamodb.optypes.DynamoDBOp)2 BaseOpDispenser (io.nosqlbench.engine.api.activityimpl.BaseOpDispenser)2 ParsedOp (io.nosqlbench.engine.api.templating.ParsedOp)2 Map (java.util.Map)2 Optional (java.util.Optional)2 LongFunction (java.util.function.LongFunction)2 GetItemSpec (com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec)1 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)1 DDBGetItemOp (io.nosqlbench.adapter.dynamodb.optypes.DDBGetItemOp)1 DDBQueryOp (io.nosqlbench.adapter.dynamodb.optypes.DDBQueryOp)1