Skip to content

Commit 54173c8

Browse files
committed
Merge branch '3.8-dev'
2 parents c4e48de + c55d9cf commit 54173c8

15 files changed

Lines changed: 385 additions & 284 deletions

File tree

CHANGELOG.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ This release also includes changes from <<release-3-7-XXX, 3.7.XXX>>.
117117
* Fixed bug in `group()` value traversal of the second `by()` where a `CollectingBarrierStep` could produce an unexpected filtering effect when `ReducingBarrierStep` or `SupplyingBarrierStep` instances were not taken into account.
118118
* Changed `DetachedFactory` to special case the handling of `ComputerAdjacentVertex` which doesn't carry properties but still needs to be detachable for OLAP cases.
119119
* Deprecated `ProfilingAware.prepareForProfiling` method preferring to simply `resetBarrierFromValueTraversal` from the `Grouping` interface after strategy application.
120+
* Added missing strategies in `gremlin-go`, updated certain strategies to take varargs and updated `GoTranslatorVisitor` for corresponding translations.
121+
* Fixed `BigInt` and `BigDecimal` parsing in `gremlin-go` cucumber test suite, fixed `UnscaledValue` type in `BigDecimal` struct and added `ParseBigDecimal` method.
120122
121123
== TinkerPop 3.7.0 (Gremfir Master of the Pan Flute)
122124

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/translator/GoTranslateVisitor.java

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,23 @@
2828
import org.apache.tinkerpop.gremlin.util.DatetimeHelper;
2929

3030
import java.time.OffsetDateTime;
31+
import java.util.Arrays;
32+
import java.util.Collections;
3133
import java.util.Date;
3234
import java.util.HashMap;
3335
import java.util.List;
3436
import java.util.Map;
37+
import java.util.Objects;
3538
import java.util.stream.Collectors;
3639

3740
public class GoTranslateVisitor extends AbstractTranslateVisitor {
3841
private final static String GO_PACKAGE_NAME = "gremlingo.";
42+
private final static List<String> STRATEGY_WITH_MAP_OPTS = Collections.unmodifiableList(Arrays.asList(
43+
"OptionsStrategy",
44+
"ReferenceElementStrategy", "ComputerFinalizationStrategy", "ProfileStrategy",
45+
"ComputerVerificationStrategy", "StandardVerificationStrategy", "VertexProgramRestrictionStrategy"));
46+
private final static List<String> STRATEGY_WITH_STRING_SLICE = Collections.unmodifiableList(Arrays.asList(
47+
"ReservedKeysVerificationStrategy", "ProductiveByStrategy"));
3948

4049
public GoTranslateVisitor() {
4150
super("g");
@@ -199,59 +208,53 @@ public Void visitTraversalStrategy(final GremlinParser.TraversalStrategyContext
199208
else {
200209
String strategyName = ctx.getChild(0).getText().equals("new") ? ctx.getChild(1).getText() : ctx.getChild(0).getText();
201210
sb.append(GO_PACKAGE_NAME).append(strategyName).append("(");
211+
if (!STRATEGY_WITH_MAP_OPTS.contains(strategyName)) { // omit strategies which use plain map instead of Config struct
212+
sb.append(GO_PACKAGE_NAME).append(strategyName).append("Config{");
213+
}
202214

203215
// get a list of all the arguments to the strategy - i.e. anything not a terminal node
204216
final List<ParseTree> configs = ctx.children.stream().
205217
filter(c -> c instanceof GremlinParser.ConfigurationContext).collect(Collectors.toList());
206218

207-
if (configs.size() > 0 && ctx.children.stream().anyMatch(t -> t.getText().equals(OptionsStrategy.class.getSimpleName()))) {
208-
sb.append("map[string]interface{}{");
209-
for (int ix = 0; ix < configs.size(); ix++) {
210-
sb.append("\"").append(configs.get(ix).getChild(0).getText()).append("\":");
211-
visit(configs.get(ix).getChild(2));
212-
if (ix < configs.size() - 1)
213-
sb.append(", ");
214-
}
215-
sb.append("}");
216-
} else {
217-
// the rest are the arguments to the strategy
218-
sb.append(GO_PACKAGE_NAME + strategyName + "Config{");
219-
for (int ix = 0; ix < configs.size(); ix++) {
220-
visit(configs.get(ix));
221-
if (ix < configs.size() - 1)
222-
sb.append(", ");
223-
}
224-
sb.append("}");
219+
// the rest are the arguments to the strategy
220+
for (int ix = 0; ix < configs.size(); ix++) {
221+
visit(configs.get(ix));
222+
if (ix < configs.size() - 1)
223+
sb.append(", ");
225224
}
226225

226+
if (!Objects.equals(strategyName, "OptionsStrategy")) {
227+
sb.append("}");
228+
}
227229
sb.append(")");
228230
}
229-
230231
return null;
231232
}
232233

233234
@Override
234-
public Void visitTraversalSourceSelfMethod_withoutStrategies(final GremlinParser.TraversalSourceSelfMethod_withoutStrategiesContext ctx) {
235-
sb.append("WithoutStrategies(");
236-
sb.append(GO_PACKAGE_NAME).append(ctx.classType().getText());
237-
238-
if (ctx.classTypeList() != null && ctx.classTypeList().classTypeExpr() != null) {
239-
for (GremlinParser.ClassTypeContext classTypeContext : ctx.classTypeList().classTypeExpr().classType()) {
240-
sb.append(", ").append(GO_PACKAGE_NAME).append(classTypeContext.getText());
235+
public Void visitConfiguration(final GremlinParser.ConfigurationContext ctx) {
236+
String parent = ctx.getParent().getText();
237+
String parentName = parent.startsWith("new") ? parent.substring(3, parent.indexOf('(')) : parent.substring(0, parent.indexOf('('));
238+
if (STRATEGY_WITH_MAP_OPTS.contains(parentName)) { // handle strategies which use plain map instead of Config struct
239+
sb.append("map[string]interface{}{\"");
240+
sb.append(ctx.getChild(0).getText());
241+
sb.append("\": ");
242+
visit(ctx.getChild(2));
243+
sb.append("}");
244+
} else {
245+
// form of three tokens of key:value to become key=value
246+
sb.append(SymbolHelper.toGo(ctx.getChild(0).getText()));
247+
sb.append(": ");
248+
visit(ctx.getChild(2));
249+
// handles strategies that takes string slices as config
250+
if (STRATEGY_WITH_STRING_SLICE.contains(parentName)) {
251+
final int ix = sb.lastIndexOf("[]interface{}");
252+
if (ix > 0) {
253+
sb.replace(ix, ix +"[]interface{}".length(), "[]string");
254+
}
241255
}
242256
}
243257

244-
sb.append(")");
245-
return null;
246-
}
247-
248-
@Override
249-
public Void visitConfiguration(final GremlinParser.ConfigurationContext ctx) {
250-
// form of three tokens of key:value to become key=value
251-
sb.append(SymbolHelper.toGo(ctx.getChild(0).getText()));
252-
sb.append(": ");
253-
visit(ctx.getChild(2));
254-
255258
// need to convert List to Set for readPartitions until TINKERPOP-3032
256259
if (ctx.getChild(0).getText().equals("readPartitions")) {
257260
final int ix = sb.lastIndexOf("ReadPartitions: [");
@@ -266,6 +269,21 @@ public Void visitConfiguration(final GremlinParser.ConfigurationContext ctx) {
266269
return null;
267270
}
268271

272+
@Override
273+
public Void visitTraversalSourceSelfMethod_withoutStrategies(final GremlinParser.TraversalSourceSelfMethod_withoutStrategiesContext ctx) {
274+
sb.append("WithoutStrategies(");
275+
sb.append(GO_PACKAGE_NAME).append(ctx.classType().getText()).append("()");
276+
277+
if (ctx.classTypeList() != null && ctx.classTypeList().classTypeExpr() != null) {
278+
for (GremlinParser.ClassTypeContext classTypeContext : ctx.classTypeList().classTypeExpr().classType()) {
279+
sb.append(", ").append(GO_PACKAGE_NAME).append(classTypeContext.getText()).append("()");
280+
}
281+
}
282+
283+
sb.append(")");
284+
return null;
285+
}
286+
269287
@Override
270288
public Void visitTraversalCardinality(final GremlinParser.TraversalCardinalityContext ctx) {
271289
// handle the enum style of cardinality if there is one child, otherwise it's the function call style

gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/translator/GremlinTranslatorTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ public static Collection<Object[]> data() {
605605
null,
606606
"g.withStrategies(new OptionsStrategy(myVar:number0))",
607607
"g.WithStrategies(new OptionsStrategy(new Dictionary<string, object> {{\"myVar\",10000},}))",
608-
"g.WithStrategies(gremlingo.OptionsStrategy(map[string]interface{}{\"myVar\":10000}))",
608+
"g.WithStrategies(gremlingo.OptionsStrategy(map[string]interface{}{\"myVar\": 10000}))",
609609
null,
610610
"g.withStrategies(OptionsStrategy.build().with(\"myVar\", 10000).create())",
611611
"g.withStrategies(new OptionsStrategy({myVar: 10000}))",
@@ -671,16 +671,26 @@ public static Collection<Object[]> data() {
671671
null,
672672
null,
673673
"g.WithoutStrategies(typeof(ReadOnlyStrategy))",
674-
"g.WithoutStrategies(gremlingo.ReadOnlyStrategy)", // go - needs TINKERPOP-3055
674+
"g.WithoutStrategies(gremlingo.ReadOnlyStrategy())", // go - needs TINKERPOP-3055
675675
null,
676676
"g.withoutStrategies(ReadOnlyStrategy.class)",
677677
"g.withoutStrategies(ReadOnlyStrategy)", // javascript needs TINKERPOP-3055
678678
"g.without_strategies(ReadOnlyStrategy)"},
679+
{"g.withStrategies(ReservedKeysVerificationStrategy(throwException: true, keys: [\"age\"])).addV(\"person\").property(\"age\", 29).property(\"name\", \"marko\")",
680+
"g.withStrategies(ReservedKeysVerificationStrategy(throwException:true, keys:[\"age\"])).addV(\"person\").property(\"age\", 29).property(\"name\", \"marko\")",
681+
"g.withStrategies(ReservedKeysVerificationStrategy(throwException:boolean0, keys:list0)).addV(string0).property(string1, number0).property(string2, string3)",
682+
"g.WithStrategies(new ReservedKeysVerificationStrategy(throwException: true, keys: new List<object> { \"age\" })).AddV(\"person\").Property(\"age\", 29).Property(\"name\", \"marko\")",
683+
"g.WithStrategies(gremlingo.ReservedKeysVerificationStrategy(gremlingo.ReservedKeysVerificationStrategyConfig{ThrowException: true, Keys: []string{\"age\"}})).AddV(\"person\").Property(\"age\", 29).Property(\"name\", \"marko\")",
684+
"g.withStrategies(new ReservedKeysVerificationStrategy(throwException:true, keys:[\"age\"])).addV(\"person\").property(\"age\", 29).property(\"name\", \"marko\")",
685+
"g.withStrategies(ReservedKeysVerificationStrategy.build().throwException(true).keys(new ArrayList<Object>() {{ add(\"age\"); }}).create()).addV(\"person\").property(\"age\", 29).property(\"name\", \"marko\")",
686+
"g.withStrategies(new ReservedKeysVerificationStrategy({throwException: true, keys: [\"age\"]})).addV(\"person\").property(\"age\", 29).property(\"name\", \"marko\")",
687+
"g.with_strategies(ReservedKeysVerificationStrategy(throw_exception=True, keys=['age'])).add_v('person').property('age', 29).property('name', 'marko')"
688+
},
679689
{"g.withoutStrategies(ReadOnlyStrategy, PathRetractionStrategy, FilterRankingStrategy)",
680690
null,
681691
null,
682692
"g.WithoutStrategies(typeof(ReadOnlyStrategy), typeof(PathRetractionStrategy), typeof(FilterRankingStrategy))",
683-
"g.WithoutStrategies(gremlingo.ReadOnlyStrategy, gremlingo.PathRetractionStrategy, gremlingo.FilterRankingStrategy)", // go - needs TINKERPOP-3055
693+
"g.WithoutStrategies(gremlingo.ReadOnlyStrategy(), gremlingo.PathRetractionStrategy(), gremlingo.FilterRankingStrategy())", // go - needs TINKERPOP-3055
684694
null,
685695
"g.withoutStrategies(ReadOnlyStrategy.class, PathRetractionStrategy.class, FilterRankingStrategy.class)",
686696
"g.withoutStrategies(ReadOnlyStrategy, PathRetractionStrategy, FilterRankingStrategy)", // javascript - needs TINKERPOP-3055

0 commit comments

Comments
 (0)