From 8fd8a6cb98b5f64cae7040ad3e9e9f24525bca09 Mon Sep 17 00:00:00 2001 From: Jonathan Shook Date: Tue, 15 Feb 2022 23:21:17 -0600 Subject: [PATCH] improve graph op mappers and pre-processors --- .../adapter/cqld4/Cqld4DriverAdapter.java | 20 +++++++++++++++++++ .../opdispensers/Cqld4GremlinOpDispenser.java | 11 ++-------- .../cqld4/opmappers/Cqld4CoreOpMapper.java | 4 ++-- .../opmappers/Cqld4FluentGraphOpMapper.java | 7 +++++-- .../cqld4/opmappers/Cqld4GremlinOpMapper.java | 6 ++++-- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/Cqld4DriverAdapter.java b/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/Cqld4DriverAdapter.java index 6910e5a6c..6028a53c3 100644 --- a/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/Cqld4DriverAdapter.java +++ b/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/Cqld4DriverAdapter.java @@ -59,6 +59,26 @@ public class Cqld4DriverAdapter extends BaseDriverAdapter { map.remove("type"); } } + if (map.containsKey("type")) { + String type = map.get("type").toString(); + if (type.equals("gremlin")&&map.containsKey("script")) { + map.put("gremlin",map.get("script").toString()); + map.remove("script"); + map.remove("type"); + } + if (type.equals("gremlin")&&map.containsKey("stmt")) { + map.put("gremlin",map.get("stmt")); + map.remove("type"); + map.remove("stmt"); + } + if (type.equals("fluent")&&map.containsKey("fluent")) { + map.remove("type"); + } + if (type.equals("fluent")&&map.containsKey("stmt")) { + map.put("fluent",map.get("stmt")); + map.remove("stmt"); + } + } return map; }); diff --git a/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opdispensers/Cqld4GremlinOpDispenser.java b/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opdispensers/Cqld4GremlinOpDispenser.java index d336b4c37..41d023627 100644 --- a/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opdispensers/Cqld4GremlinOpDispenser.java +++ b/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opdispensers/Cqld4GremlinOpDispenser.java @@ -16,7 +16,7 @@ public class Cqld4GremlinOpDispenser extends BaseOpDispenser private final LongFunction sessionFunc; private final LongFunction diagFunc; - public Cqld4GremlinOpDispenser(LongFunction sessionFunc, ParsedOp cmd) { + public Cqld4GremlinOpDispenser(LongFunction sessionFunc, LongFunction targetFunction, ParsedOp cmd) { super(cmd); this.sessionFunc = sessionFunc; this.diagFunc = cmd.getAsFunctionOr("diag", 0L); @@ -31,15 +31,8 @@ public class Cqld4GremlinOpDispenser extends BaseOpDispenser func = l -> finalFunc.apply(l).setGraphName(stringLongFunction.apply(l)); } - // script - Optional> scriptFunc = cmd.getAsOptionalFunction("script"); - if (scriptFunc.isPresent()) { - LongFunction finalFunc = func; - func = l -> finalFunc.apply(l).setScript(scriptFunc.get().apply(l)); - } - LongFunction finalFunc = func; - this.stmtFunc = l -> finalFunc.apply(l).build(); + this.stmtFunc = l -> finalFunc.apply(l).setScript(targetFunction.apply(l)).build(); } diff --git a/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opmappers/Cqld4CoreOpMapper.java b/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opmappers/Cqld4CoreOpMapper.java index 62c8db367..a0821daae 100644 --- a/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opmappers/Cqld4CoreOpMapper.java +++ b/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opmappers/Cqld4CoreOpMapper.java @@ -48,8 +48,8 @@ public class Cqld4CoreOpMapper implements OpMapper { case raw -> new CqlD4RawStmtMapper(sessionFunc, target.targetFunction).apply(cmd); case simple -> new CqlD4CqlSimpleStmtMapper(sessionFunc, target.targetFunction).apply(cmd); case prepared -> new CqlD4PreparedStmtMapper(sessionFunc, target).apply(cmd); - case gremlin -> new Cqld4GremlinOpMapper(sessionFunc).apply(cmd); - case fluent -> new Cqld4FluentGraphOpMapper(sessionFunc).apply(cmd); + case gremlin -> new Cqld4GremlinOpMapper(sessionFunc, target.targetFunction).apply(cmd); + case fluent -> new Cqld4FluentGraphOpMapper(sessionFunc, target).apply(cmd); }; } diff --git a/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opmappers/Cqld4FluentGraphOpMapper.java b/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opmappers/Cqld4FluentGraphOpMapper.java index b408d3916..11beb0f48 100644 --- a/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opmappers/Cqld4FluentGraphOpMapper.java +++ b/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opmappers/Cqld4FluentGraphOpMapper.java @@ -10,6 +10,7 @@ import io.nosqlbench.engine.api.activityimpl.OpDispenser; import io.nosqlbench.engine.api.activityimpl.OpMapper; import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op; import io.nosqlbench.engine.api.templating.ParsedOp; +import io.nosqlbench.engine.api.templating.TypeAndTarget; import io.nosqlbench.virtdata.core.bindings.Bindings; import io.nosqlbench.virtdata.core.bindings.BindingsTemplate; import io.nosqlbench.virtdata.core.templates.ParsedTemplate; @@ -30,17 +31,19 @@ public class Cqld4FluentGraphOpMapper implements OpMapper { private final static Logger logger = LogManager.getLogger(Cqld4FluentGraphOpMapper.class); private final LongFunction sessionFunc; + private final TypeAndTarget target; private GraphTraversalSource gtsPlaceHolder; - public Cqld4FluentGraphOpMapper(LongFunction sessionFunc) { + public Cqld4FluentGraphOpMapper(LongFunction sessionFunc, TypeAndTarget target) { this.sessionFunc = sessionFunc; + this.target = target; } @Override public OpDispenser apply(ParsedOp cmd) { GraphTraversalSource g = DseGraph.g; - ParsedTemplate fluent = cmd.getAsTemplate("fluent").orElseThrow(); + ParsedTemplate fluent = cmd.getAsTemplate(target.field).orElseThrow(); String scriptBodyWithRawVarRefs = fluent.getPositionalStatement(); CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); diff --git a/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opmappers/Cqld4GremlinOpMapper.java b/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opmappers/Cqld4GremlinOpMapper.java index a7aedd022..21c850ee8 100644 --- a/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opmappers/Cqld4GremlinOpMapper.java +++ b/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/opmappers/Cqld4GremlinOpMapper.java @@ -11,12 +11,14 @@ import java.util.function.LongFunction; public class Cqld4GremlinOpMapper implements OpMapper { private final LongFunction sessionFunc; + private final LongFunction targetFunction; - public Cqld4GremlinOpMapper(LongFunction session) { + public Cqld4GremlinOpMapper(LongFunction session, LongFunction targetFunction) { this.sessionFunc = session; + this.targetFunction = targetFunction; } public OpDispenser apply(ParsedOp cmd) { - return new Cqld4GremlinOpDispenser(sessionFunc, cmd); + return new Cqld4GremlinOpDispenser(sessionFunc, targetFunction, cmd); } }