Skip to content

Commit

Permalink
remove option(Merge, GValue<Map>, Cardinality) overload from GraphTra…
Browse files Browse the repository at this point in the history
…versal
  • Loading branch information
Cole-Greer committed Dec 6, 2024
1 parent 25541fd commit a81a955
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,10 @@ protected void notImplemented(final ParseTree ctx) {
* {@inheritDoc}
*/
@Override public T visitGenericLiteralMap(final GremlinParser.GenericLiteralMapContext ctx) { notImplemented(ctx); return null; }
/**
* {@inheritDoc}
*/
@Override public T visitNullableGenericLiteralMap(final GremlinParser.NullableGenericLiteralMapContext ctx) { notImplemented(ctx); return null; }
/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,20 +1246,12 @@ public GraphTraversal visitTraversalMethod_option_Merge_Traversal(final GremlinP
*/
@Override
public Traversal visitTraversalMethod_option_Merge_Map_Cardinality(final GremlinParser.TraversalMethod_option_Merge_Map_CardinalityContext ctx) {
if (ctx.genericLiteralMapNullableArgument().nullLiteral() != null) {
if (ctx.nullableGenericLiteralMap().nullLiteral() != null) {
return this.graphTraversal.option(TraversalEnumParser.parseTraversalEnumFromContext(Merge.class, ctx.traversalMerge()), (Map) null);
}

final Object literalOrVar = antlr.argumentVisitor.visitGenericLiteralMapNullableArgument(ctx.genericLiteralMapNullableArgument());
if (GValue.valueInstanceOf(literalOrVar, GType.MAP)) {
return graphTraversal.option(TraversalEnumParser.parseTraversalEnumFromContext(Merge.class, ctx.traversalMerge()),
(GValue<Map<Object, Object>>) literalOrVar,
TraversalEnumParser.parseTraversalEnumFromContext(Cardinality.class, ctx.traversalCardinality()));
} else {
return graphTraversal.option(TraversalEnumParser.parseTraversalEnumFromContext(Merge.class, ctx.traversalMerge()),
(Map<Object, Object>) literalOrVar,
TraversalEnumParser.parseTraversalEnumFromContext(Cardinality.class, ctx.traversalCardinality()));
}
return graphTraversal.option(TraversalEnumParser.parseTraversalEnumFromContext(Merge.class, ctx.traversalMerge()),
antlr.genericVisitor.parseMap(ctx.nullableGenericLiteralMap().genericLiteralMap()),
TraversalEnumParser.parseTraversalEnumFromContext(Cardinality.class, ctx.traversalCardinality()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,11 @@ public Void visitGenericLiteralMapNullableArgument(final GremlinParser.GenericLi
return visitChildren(ctx);
}

@Override
public Void visitNullableGenericLiteralMap(final GremlinParser.NullableGenericLiteralMapContext ctx) {
return visitChildren(ctx);
}

@Override
public Void visitStructureVertexArgument(final GremlinParser.StructureVertexArgumentContext ctx) {
return visitChildren(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4533,24 +4533,6 @@ public default <M, E2> GraphTraversal<S, E> option(final M token, final GValue<M
return this;
}

/**
* This is a step modulator to a {@link TraversalOptionParent} like {@code choose()} or {@code mergeV()} where the
* provided argument associated to the {@code token} is applied according to the semantics of the step. Please see
* the documentation of such steps to understand the usage context.
*
* @param m Provides a {@code Map} as the option which is the same as doing {@code constant(m)}.
* @return the traversal with the modulated step
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#mergev-step" target="_blank">Reference Documentation - MergeV Step</a>
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#mergee-step" target="_blank">Reference Documentation - MergeE Step</a>
* @since 4.0.0
*/
public default <M, E2> GraphTraversal<S, E> option(final Merge merge, final GValue<Map<Object, Object>> m, final VertexProperty.Cardinality cardinality) {
this.asAdmin().getGremlinLang().addStep(GraphTraversal.Symbols.option, merge, m, cardinality);

((TraversalOptionParent<M, E, E2>) this.asAdmin().getEndStep()).addChildOption((M) merge, (Traversal.Admin<E, E2>) new ConstantTraversal<>(m).asAdmin());
return this;
}

////

///////////////////// IO STEPS /////////////////////
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion gremlin-language/src/main/antlr4/Gremlin.g4
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ traversalMethod_not
traversalMethod_option
: 'option' LPAREN traversalPredicate COMMA nestedTraversal RPAREN #traversalMethod_option_Predicate_Traversal
| 'option' LPAREN traversalMerge COMMA genericLiteralMapNullableArgument RPAREN #traversalMethod_option_Merge_Map
| 'option' LPAREN traversalMerge COMMA genericLiteralMapNullableArgument COMMA traversalCardinality RPAREN #traversalMethod_option_Merge_Map_Cardinality
| 'option' LPAREN traversalMerge COMMA nullableGenericLiteralMap COMMA traversalCardinality RPAREN #traversalMethod_option_Merge_Map_Cardinality
| 'option' LPAREN traversalMerge COMMA nestedTraversal RPAREN #traversalMethod_option_Merge_Traversal
| 'option' LPAREN genericLiteralArgument COMMA nestedTraversal RPAREN #traversalMethod_option_Object_Traversal
| 'option' LPAREN nestedTraversal RPAREN #traversalMethod_option_Traversal
Expand Down Expand Up @@ -1493,6 +1493,11 @@ genericLiteralMapNullableArgument
| variable
;

nullableGenericLiteralMap
: genericLiteralMap
| nullLiteral
;

structureVertexArgument
: structureVertex
| variable
Expand Down
1 change: 0 additions & 1 deletion gremlin-python/src/main/python/radish/gremlin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,6 @@
'g_mergeVXname_markoX_optionXonMatch_age_singleX33XX': [(lambda g:g.add_v('person').property('name', 'marko').property(Cardinality.list_, 'age', 29).property(Cardinality.list_, 'age', 31).property(Cardinality.list_, 'age', 32)), (lambda g:g.merge_v({ 'name': 'marko' }).option(Merge.on_match, { 'age': CardinalityValue.single(33) })), (lambda g:g.V().has('person', 'name', 'marko').has('age', 33)), (lambda g:g.V().has('person', 'name', 'marko').has('age')), (lambda g:g.V().has('person', 'name', 'marko').properties('age'))],
'g_mergeVXname_markoX_optionXonMatch_age_33_singleX': [(lambda g:g.add_v('person').property('name', 'marko').property(Cardinality.list_, 'age', 29).property(Cardinality.list_, 'age', 31).property(Cardinality.list_, 'age', 32)), (lambda g:g.merge_v({ 'name': 'marko' }).option(Merge.on_match, { 'age': 33 }, Cardinality.single)), (lambda g:g.V().has('person', 'name', 'marko').has('age', 33)), (lambda g:g.V().has('person', 'name', 'marko').has('age')), (lambda g:g.V().has('person', 'name', 'marko').properties('age'))],
'g_mergeVXname_markoX_optionXonMatch_name_allen_age_setX31X_singleX': [(lambda g:g.add_v('person').property('name', 'marko').property(Cardinality.list_, 'age', 29).property(Cardinality.list_, 'age', 31).property(Cardinality.list_, 'age', 32)), (lambda g:g.merge_v({ 'name': 'marko' }).option(Merge.on_match, { 'name': 'allen', 'age': CardinalityValue.set_(31) }, Cardinality.single)), (lambda g:g.V().has('person', 'name', 'marko')), (lambda g:g.V().has('person', 'name', 'allen').has('age', 31)), (lambda g:g.V().has('person', 'name', 'allen').has('age')), (lambda g:g.V().has('person', 'name', 'allen').properties('age'))],
'g_mergeVXname_markoX_optionXonMatch_name_allen_var_singleX': [(lambda g, xx1=None:g.add_v('person').property('name', 'marko')), (lambda g, xx1=None:g.merge_v({ 'name': 'marko' }).option(Merge.on_match, xx1, Cardinality.single)), (lambda g, xx1=None:g.V().has('person', 'name', 'marko')), (lambda g, xx1=None:g.V().has('person', 'name', 'allen'))],
'g_mergeVXname_markoX_optionXonMatch_name_allen_age_singleX31X_singleX': [(lambda g:g.add_v('person').property('name', 'marko').property(Cardinality.list_, 'age', 29).property(Cardinality.list_, 'age', 31).property(Cardinality.list_, 'age', 32)), (lambda g:g.merge_v({ 'name': 'marko' }).option(Merge.on_match, { 'name': 'allen', 'age': CardinalityValue.single(31) }, Cardinality.single)), (lambda g:g.V().has('person', 'name', 'marko')), (lambda g:g.V().has('person', 'name', 'allen').has('age', 33)), (lambda g:g.V().has('person', 'name', 'allen').has('age', 31)), (lambda g:g.V().has('person', 'name', 'allen').has('age')), (lambda g:g.V().has('person', 'name', 'allen').properties('age'))],
'g_mergeVXname_aliceX_optionXonCreate_age_singleX81XX': [(lambda g:g.merge_v({ 'name': 'alice', T.label: 'person' }).option(Merge.on_create, { 'age': CardinalityValue.single(81) })), (lambda g:g.V().has('person', 'name', 'alice').has('age', 81)), (lambda g:g.V().has('person', 'name', 'alice').has('age')), (lambda g:g.V().has('person', 'name', 'alice').properties('age'))],
'g_mergeVXname_aliceX_optionXonCreate_age_setX81XX': [(lambda g:g.merge_v({ 'name': 'alice', T.label: 'person' }).option(Merge.on_create, { 'age': CardinalityValue.set_(81) })), (lambda g:g.V().has('person', 'name', 'alice').has('age', 81)), (lambda g:g.V().has('person', 'name', 'alice').has('age')), (lambda g:g.V().has('person', 'name', 'alice').properties('age'))],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ Feature: Step - mergeV()
Then the result should have a count of 1
And the graph should return 1 for count of "g.V()"

@GremlinLangScriptOnly
Scenario: g_V_mergeVXnullX
Given the empty graph
And the graph initializer of
Expand Down Expand Up @@ -955,22 +954,6 @@ Feature: Step - mergeV()
And the graph should return 1 for count of "g.V().has(\"person\",\"name\",\"allen\").has(\"age\")"
And the graph should return 3 for count of "g.V().has(\"person\",\"name\",\"allen\").properties(\"age\")"

Scenario: g_mergeVXname_markoX_optionXonMatch_name_allen_var_singleX
Given the empty graph
And the graph initializer of
"""
g.addV("person").property("name", "marko")
"""
And using the parameter xx1 defined as "m[{\"name\":\"allen\"}]"
And the traversal of
"""
g.mergeV([name: "marko"]).option(Merge.onMatch, xx1, single)
"""
When iterated to list
Then the result should have a count of 1
And the graph should return 0 for count of "g.V().has(\"person\",\"name\",\"marko\")"
And the graph should return 1 for count of "g.V().has(\"person\",\"name\",\"allen\")"

@MultiProperties
Scenario: g_mergeVXname_markoX_optionXonMatch_name_allen_age_singleX31X_singleX
Given the empty graph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Feature: Step - inject()
| result |
| l[d[1].i,d[3].i,d[100].i,d[300].i] |

@GraphComputerVerificationInjectionNotSupported @GremlinLangScriptOnly
@GraphComputerVerificationInjectionNotSupported
Scenario: g_injectX1_3_100_300X_set
Given the modern graph
And the traversal of
Expand All @@ -288,7 +288,7 @@ Feature: Step - inject()
| result |
| s[d[100].i,d[300].i,d[1].i,d[3].i] |

@GraphComputerVerificationInjectionNotSupported @GremlinLangScriptOnly
@GraphComputerVerificationInjectionNotSupported
Scenario: g_injectX1_1X_set
Given the modern graph
And the traversal of
Expand Down

0 comments on commit a81a955

Please sign in to comment.