Skip to content

Commit fbb9f29

Browse files
Cole-Greerxiazcy
authored andcommitted
Remove GenericArgument from from() and to().
from() and to() will now only accept Strings (alias for __.select()) and Traversals. If users wish to pass a vertex id, they may embed it in __.V() or __.constant(). The primary motivation here is to ensure consistent behaviour accross providers regardless of if their id types are numerics, strings, or other.
1 parent 8d86ff6 commit fbb9f29

13 files changed

Lines changed: 47 additions & 118 deletions

File tree

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/DefaultGremlinBaseVisitor.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,6 @@ protected void notImplemented(final ParseTree ctx) {
407407
* {@inheritDoc}
408408
*/
409409
@Override public T visitTraversalMethod_from_String(final GremlinParser.TraversalMethod_from_StringContext ctx) { notImplemented(ctx); return null; }
410-
/**
411-
* {@inheritDoc}
412-
*/
413-
@Override public T visitTraversalMethod_from_GenricArgument(final GremlinParser.TraversalMethod_from_GenricArgumentContext ctx) { return null; }
414410
/**
415411
* {@inheritDoc}
416412
*/
@@ -847,10 +843,6 @@ protected void notImplemented(final ParseTree ctx) {
847843
* {@inheritDoc}
848844
*/
849845
@Override public T visitTraversalMethod_to_String(final GremlinParser.TraversalMethod_to_StringContext ctx) { notImplemented(ctx); return null; }
850-
/**
851-
* {@inheritDoc}
852-
*/
853-
@Override public T visitTraversalMethod_to_GenricArgument(final GremlinParser.TraversalMethod_to_GenricArgumentContext ctx) { notImplemented(ctx); return null; }
854846
/**
855847
* {@inheritDoc}
856848
*/

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitor.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,22 +1883,6 @@ public Traversal visitTraversalMethod_option_Predicate_Traversal(final GremlinPa
18831883
antlr.tvisitor.visitNestedTraversal(ctx.nestedTraversal()));
18841884
}
18851885

1886-
/**
1887-
* {@inheritDoc}
1888-
*/
1889-
@Override
1890-
public GraphTraversal visitTraversalMethod_from_GenricArgument(final GremlinParser.TraversalMethod_from_GenricArgumentContext ctx) {
1891-
return graphTraversal.from(antlr.argumentVisitor.visitGenericArgument(ctx.genericArgument()));
1892-
}
1893-
1894-
/**
1895-
* {@inheritDoc}
1896-
*/
1897-
@Override
1898-
public Traversal visitTraversalMethod_to_GenricArgument(final GremlinParser.TraversalMethod_to_GenricArgumentContext ctx) {
1899-
return graphTraversal.to(antlr.argumentVisitor.visitGenericArgument(ctx.genericArgument()));
1900-
}
1901-
19021886
/**
19031887
* {@inheritDoc}
19041888
*/

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,14 +1604,14 @@ public default GraphTraversal<S, E> from(final String fromStepLabel) {
16041604
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - From Step</a>
16051605
* @since 3.8.0
16061606
*/
1607-
public default GraphTraversal<S, E> from(final GValue<Vertex> fromVertex) {
1607+
public default GraphTraversal<S, E> from(final GValue<?> fromVertex) {
16081608
final Step<?,?> prev = this.asAdmin().getEndStep();
16091609
if (!(prev instanceof FromToModulating))
16101610
throw new IllegalArgumentException(String.format(
16111611
"The from() step cannot follow %s", prev.getClass().getSimpleName()));
16121612

16131613
this.asAdmin().getBytecode().addStep(Symbols.from, fromVertex);
1614-
((FromToModulating) prev).addFrom(new GValueConstantTraversal<S, Vertex>(fromVertex));
1614+
((FromToModulating) prev).addFrom(new GValueConstantTraversal<>(fromVertex));
16151615
return this;
16161616
}
16171617

@@ -1663,14 +1663,14 @@ public default GraphTraversal<S, E> to(final String toStepLabel) {
16631663
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - From Step</a>
16641664
* @since 3.8.0
16651665
*/
1666-
public default GraphTraversal<S, E> to(final GValue<Vertex> toVertex) {
1666+
public default GraphTraversal<S, E> to(final GValue<?> toVertex) {
16671667
final Step<?,?> prev = this.asAdmin().getEndStep();
16681668
if (!(prev instanceof FromToModulating))
16691669
throw new IllegalArgumentException(String.format(
16701670
"The to() step cannot follow %s", prev.getClass().getSimpleName()));
16711671

16721672
this.asAdmin().getBytecode().addStep(Symbols.to, toVertex);
1673-
((FromToModulating) prev).addTo(new GValueConstantTraversal<S, Vertex>(toVertex));
1673+
((FromToModulating) prev).addTo(new GValueConstantTraversal<>(toVertex));
16741674
return this;
16751675
}
16761676

@@ -1683,7 +1683,7 @@ public default GraphTraversal<S, E> to(final GValue<Vertex> toVertex) {
16831683
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - From Step</a>
16841684
* @since 3.1.0-incubating
16851685
*/
1686-
public default GraphTraversal<S, E> to(final Traversal<?, Object> toVertex) {
1686+
public default GraphTraversal<S, E> to(final Traversal<?, ?> toVertex) {
16871687
final Step<?,?> prev = this.asAdmin().getEndStep();
16881688
if (!(prev instanceof FromToModulating))
16891689
throw new IllegalArgumentException(String.format(
@@ -1703,7 +1703,7 @@ public default GraphTraversal<S, E> to(final Traversal<?, Object> toVertex) {
17031703
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - From Step</a>
17041704
* @since 3.1.0-incubating
17051705
*/
1706-
public default GraphTraversal<S, E> from(final Traversal<?, Object> fromVertex) {
1706+
public default GraphTraversal<S, E> from(final Traversal<?, ?> fromVertex) {
17071707
final Step<?,?> prev = this.asAdmin().getEndStep();
17081708
if (!(prev instanceof FromToModulating))
17091709
throw new IllegalArgumentException(String.format(
@@ -1723,13 +1723,7 @@ public default GraphTraversal<S, E> from(final Traversal<?, Object> fromVertex)
17231723
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - From Step</a>
17241724
* @since 3.3.0
17251725
*/
1726-
public default GraphTraversal<S, E> to(final Object toVertex) {
1727-
if (toVertex instanceof String) {
1728-
return this.to((String) toVertex);
1729-
} else if (toVertex instanceof Traversal) {
1730-
this.to((Traversal<?, Object>)toVertex);
1731-
return this;
1732-
}
1726+
public default GraphTraversal<S, E> to(final Vertex toVertex) {
17331727
final Step<?,?> prev = this.asAdmin().getEndStep();
17341728
if (!(prev instanceof FromToModulating))
17351729
throw new IllegalArgumentException(String.format(
@@ -1742,34 +1736,6 @@ public default GraphTraversal<S, E> to(final Object toVertex) {
17421736
return this;
17431737
}
17441738

1745-
/**
1746-
* When used as a modifier to {@link #addE(String)} this method specifies the traversal to use for selecting the
1747-
* outgoing vertex of the newly added {@link Edge}.
1748-
*
1749-
* @param fromVertex the vertex for selecting the outgoing vertex
1750-
* @return the traversal with the modified {@link AddEdgeStepContract}
1751-
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - From Step</a>
1752-
* @since 3.3.0
1753-
*/
1754-
public default GraphTraversal<S, E> from(final Object fromVertex) {
1755-
if (fromVertex instanceof String) {
1756-
return this.from((String) fromVertex);
1757-
} else if (fromVertex instanceof Traversal) {
1758-
this.from((Traversal<?, Object>)fromVertex);
1759-
return this;
1760-
}
1761-
final Step<?,?> prev = this.asAdmin().getEndStep();
1762-
if (!(prev instanceof FromToModulating))
1763-
throw new IllegalArgumentException(String.format(
1764-
"The from() step cannot follow %s", prev.getClass().getSimpleName()));
1765-
1766-
this.asAdmin().getBytecode().addStep(Symbols.from, fromVertex);
1767-
((FromToModulating) prev).addFrom(fromVertex instanceof GValue ?
1768-
new GValueConstantTraversal<>((GValue<Object>) fromVertex) :
1769-
__.constant(fromVertex).asAdmin());
1770-
return this;
1771-
}
1772-
17731739
/**
17741740
* Map the {@link Traverser} to a {@link Double} according to the mathematical expression provided in the argument.
17751741
*

gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/TraversalParentTest.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,6 @@ public static Iterable<Object[]> data() {
208208
List.of(__.constant("name"), __.constant("cole")),
209209
null, null
210210
},
211-
{AddEdgeStepContract.class,
212-
g.addE("label").from(1).to(2).property("name", __.constant("cole")),
213-
List.of(),
214-
List.of(__.constant("cole"), __.constant(1), __.constant(2)),
215-
null, null
216-
},
217211
{AddEdgeStepContract.class,
218212
g.addE("label").from(__.V(1)).to(__.V(2))
219213
.property("name", __.constant("cole"))
@@ -235,15 +229,9 @@ public static Iterable<Object[]> data() {
235229
null, null
236230
},
237231
{AddEdgeStepContract.class,
238-
g.addE("label").from(1).to(2).property(__.constant("name"), __.constant("cole")),
239-
List.of(),
240-
List.of(__.constant("name"), __.constant("cole"), __.constant(1), __.constant(2)),
241-
null, null
242-
},
243-
{AddEdgeStepContract.class,
244-
g.inject(1).addE("label").from(1).to(2).property("name", __.constant("cole")),
232+
g.addE("label").from(__.V(1)).to(__.V(2)).property(__.constant("name"), __.constant("cole")),
245233
List.of(),
246-
List.of(__.constant("cole"), __.constant(1), __.constant(2)),
234+
List.of(__.constant("name"), __.constant("cole"), __.V(1), __.V(2)),
247235
null, null
248236
},
249237
{AddEdgeStepContract.class,
@@ -259,9 +247,9 @@ public static Iterable<Object[]> data() {
259247
null, null
260248
},
261249
{AddEdgeStepContract.class,
262-
g.inject(1).addE("label").from(1).to(2).property(__.constant("name"), __.constant("cole")),
250+
g.inject(1).addE("label").from(__.V(1)).to(__.V(2)).property(__.constant("name"), __.constant("cole")),
263251
List.of(),
264-
List.of(__.constant("name"), __.constant("cole"), __.constant(1), __.constant(2)),
252+
List.of(__.constant("name"), __.constant("cole"), __.V(1), __.V(2)),
265253
null, null
266254
},
267255
{CallStepContract.class,

gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStartStepTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
3030
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
3131
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
32+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
3233
import org.apache.tinkerpop.gremlin.process.traversal.step.GValue;
3334
import org.apache.tinkerpop.gremlin.process.traversal.step.GValueStepTest;
3435
import org.apache.tinkerpop.gremlin.structure.Edge;
@@ -55,7 +56,7 @@ protected List<Traversal> getTraversals() {
5556
g.addE("created").property("a", "b"),
5657
g.addE("knows").property("a", "b").property("c", "e"),
5758
g.addE("knows").property("c", "e"),
58-
g.addE("knows").from(1).to(2).property("a", "b"),
59+
g.addE("knows").from(__.V(1)).to(__.V(2)).property("a", "b"),
5960
g.addE(GValue.of("label", "knows")).property("a", "b"),
6061
g.addE(GValue.of("label", "created")).property("a", GValue.of("prop", "b")),
6162
g.addE(GValue.of("label", "knows")).property("a", GValue.of("prop1", "b")).property("c", GValue.of("prop2", "e")),
@@ -213,8 +214,8 @@ public void getGValuesShouldReturnAllGValues() {
213214
@Test
214215
public void getGValuesNonShouldReturnEmptyCollection() {
215216
GraphTraversal.Admin<Edge, Edge> traversal = g.addE("likes")
216-
.from(1)
217-
.to(2)
217+
.from(__.V(1))
218+
.to(__.V(2))
218219
.property(T.id, "1234")
219220
.property("rating", "great")
220221
.asAdmin();

gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStepTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected List<Traversal> getTraversals() {
6060
__.addE("created").property("a", "b"),
6161
__.addE("knows").property("a", "b").property("c", "e"),
6262
__.addE("knows").property("c", "e"),
63-
__.addE("knows").from(1).to(2).property("a", "b"),
63+
__.addE("knows").from(__.V(1)).to(__.V(2)).property("a", "b"),
6464
__.addE(GValue.of("label", "knows")).property("a", "b"),
6565
__.addE(GValue.of("label", "created")).property("a", GValue.of("prop", "b")),
6666
__.addE(GValue.of("label", "knows")).property("a", GValue.of("prop1", "b")).property("c", GValue.of("prop2", "e")),
@@ -306,8 +306,8 @@ public void getGValuesShouldReturnAllGValues() {
306306
@Test
307307
public void getGValuesNonShouldReturnEmptyCollection() {
308308
GraphTraversal.Admin<Object, Edge> traversal = __.addE("likes")
309-
.from(1)
310-
.to(2)
309+
.from(__.V(1))
310+
.to(__.V(2))
311311
.property(T.id, "1234")
312312
.property("rating", "great")
313313
.asAdmin();

0 commit comments

Comments
 (0)