add missing list templating logic to fix imports bug

This commit is contained in:
Jonathan Shook
2022-02-17 11:11:39 -06:00
parent 549b143fc7
commit 4b6019e7d0
3 changed files with 23 additions and 14 deletions

View File

@@ -11,6 +11,7 @@ import io.nosqlbench.engine.api.activityimpl.OpMapper;
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op; import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
import io.nosqlbench.engine.api.templating.ParsedOp; import io.nosqlbench.engine.api.templating.ParsedOp;
import io.nosqlbench.engine.api.templating.TypeAndTarget; import io.nosqlbench.engine.api.templating.TypeAndTarget;
import io.nosqlbench.nb.api.errors.OpConfigError;
import io.nosqlbench.virtdata.core.bindings.Bindings; import io.nosqlbench.virtdata.core.bindings.Bindings;
import io.nosqlbench.virtdata.core.bindings.BindingsTemplate; import io.nosqlbench.virtdata.core.bindings.BindingsTemplate;
import io.nosqlbench.virtdata.core.templates.ParsedTemplate; import io.nosqlbench.virtdata.core.templates.ParsedTemplate;
@@ -20,10 +21,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSo
import org.codehaus.groovy.control.CompilerConfiguration; import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ImportCustomizer; import org.codehaus.groovy.control.customizers.ImportCustomizer;
import java.util.ArrayList; import java.util.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.LongFunction; import java.util.function.LongFunction;
import java.util.function.Supplier; import java.util.function.Supplier;
@@ -48,16 +46,16 @@ public class Cqld4FluentGraphOpMapper implements OpMapper<Op> {
CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
cmd.getOptionalStaticValue("imports", List.class).ifPresent( if (cmd.isDynamic("imports")) {
l -> { throw new OpConfigError("You may only define imports as a static list. Dynamic values are not allowed.");
ArrayList<String> stringList = new ArrayList<>(); }
l.forEach(o -> stringList.add(o.toString()));
String[] verifiedClasses = expandClassNames(l); List imports = cmd.getOptionalStaticValue("imports", List.class)
ImportCustomizer importer = new ImportCustomizer(); .orElse(List.of("org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__"));
importer.addImports(verifiedClasses); String[] verifiedClasses = expandClassNames(imports);
compilerConfiguration.addCompilationCustomizers(importer); ImportCustomizer importer = new ImportCustomizer();
} importer.addImports(verifiedClasses);
); compilerConfiguration.addCompilationCustomizers(importer);
Supplier<Script> supplier = () -> { Supplier<Script> supplier = () -> {
groovy.lang.Binding groovyBindings = new Binding(new LinkedHashMap<String, Object>(Map.of("g", g))); groovy.lang.Binding groovyBindings = new Binding(new LinkedHashMap<String, Object>(Map.of("g", g)));

View File

@@ -121,6 +121,10 @@ names for the classic form have not changed.
example-fluent-graph-stmt: example-fluent-graph-stmt:
fluent: >- fluent: >-
g.V().hasLabel("device").has("deviceid", UUID.fromString({deviceid})) g.V().hasLabel("device").has("deviceid", UUID.fromString({deviceid}))
# if imports are not specified, the following is auto imported.
# if imports are specified, you must also provide the __ class if needed
imports:
- org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__
# gremlin statement using string API (not recommended) # gremlin statement using string API (not recommended)
example-raw-gremlin-stmt: example-raw-gremlin-stmt:

View File

@@ -121,6 +121,13 @@ public class ParsedTemplateMap implements LongFunction<Map<String, ?>>, StaticFi
} else if (v instanceof List) { } else if (v instanceof List) {
List<Object> sublist = (List<Object>) v; List<Object> sublist = (List<Object>) v;
ParsedTemplateList subtpl = new ParsedTemplateList(sublist, bindings, cfgsources); ParsedTemplateList subtpl = new ParsedTemplateList(sublist, bindings, cfgsources);
if (subtpl.isStatic()) {
statics.put(k, sublist);
protomap.put(k, sublist);
} else {
dynamics.put(k,subtpl);
protomap.put(k,null);
}
} else { } else {
// Eventually, nested and mixed static dynamic structure could be supported, but // Eventually, nested and mixed static dynamic structure could be supported, but
// it would be complex to implement and also not that efficient, so let's just copy // it would be complex to implement and also not that efficient, so let's just copy