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.templating.ParsedOp;
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.BindingsTemplate;
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.customizers.ImportCustomizer;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.LongFunction;
import java.util.function.Supplier;
@ -48,16 +46,16 @@ public class Cqld4FluentGraphOpMapper implements OpMapper<Op> {
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
cmd.getOptionalStaticValue("imports", List.class).ifPresent(
l -> {
ArrayList<String> stringList = new ArrayList<>();
l.forEach(o -> stringList.add(o.toString()));
String[] verifiedClasses = expandClassNames(l);
ImportCustomizer importer = new ImportCustomizer();
importer.addImports(verifiedClasses);
compilerConfiguration.addCompilationCustomizers(importer);
}
);
if (cmd.isDynamic("imports")) {
throw new OpConfigError("You may only define imports as a static list. Dynamic values are not allowed.");
}
List imports = cmd.getOptionalStaticValue("imports", List.class)
.orElse(List.of("org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__"));
String[] verifiedClasses = expandClassNames(imports);
ImportCustomizer importer = new ImportCustomizer();
importer.addImports(verifiedClasses);
compilerConfiguration.addCompilationCustomizers(importer);
Supplier<Script> supplier = () -> {
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:
fluent: >-
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)
example-raw-gremlin-stmt:

View File

@ -121,6 +121,13 @@ public class ParsedTemplateMap implements LongFunction<Map<String, ?>>, StaticFi
} else if (v instanceof List) {
List<Object> sublist = (List<Object>) v;
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 {
// 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