You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by co...@apache.org on 2025/09/26 20:55:52 UTC
(tinkerpop) 02/02: CTR avoid boxing label and elementId as Traversals in AddVertex and AddEdge step placeholders
This is an automated email from the ASF dual-hosted git repository.
colegreer pushed a commit to branch fixTraversalBoxingInPlaceholders
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 2b0c758f90aef1c26970ded826c9ee65a0aa137e
Author: Cole-Greer <Co...@improving.com>
AuthorDate: Fri Sep 26 13:54:09 2025 -0700
CTR avoid boxing label and elementId as Traversals in AddVertex and AddEdge step placeholders
---
.../traversal/dsl/graph/GraphTraversal.java | 40 +++---
.../step/map/AbstractAddEdgeStepPlaceholder.java | 5 +
.../map/AbstractAddElementStepPlaceholder.java | 148 +++++++++++----------
.../step/map/AbstractAddVertexStepPlaceholder.java | 20 +--
.../traversal/step/map/AddEdgeStartStep.java | 5 +
.../step/map/AddEdgeStartStepPlaceholder.java | 9 +-
.../process/traversal/step/map/AddEdgeStep.java | 5 +
.../traversal/step/map/AddEdgeStepPlaceholder.java | 9 +-
.../traversal/step/map/AddElementStepContract.java | 2 +
.../traversal/step/map/AddVertexStartStep.java | 5 +
.../step/map/AddVertexStartStepPlaceholder.java | 10 +-
.../process/traversal/step/map/AddVertexStep.java | 5 +
.../step/map/AddVertexStepPlaceholder.java | 9 +-
.../traversal/step/TraversalParentTest.java | 30 ++---
.../ReservedKeysVerificationStrategyTest.java | 1 -
15 files changed, 181 insertions(+), 122 deletions(-)
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index a6f63953aa..d493ec805d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -99,9 +99,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.filter.TimeLimitStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.WherePredicateStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.WhereTraversalStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddEdgeStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStartStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.AsBoolStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.AsDateStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.AsNumberStep;
@@ -189,7 +186,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.TrimGlobalStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.TrimLocalStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.UnfoldStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AddPropertyStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AggregateGlobalStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.FailStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GroupCountSideEffectStep;
@@ -1374,7 +1370,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* Adds a {@link Vertex}.
*
* @param vertexLabel the label of the {@link Vertex} to add
- * @return the traversal with the {@link AddVertexStep} added
+ * @return the traversal with the {@link AddVertexStepContract} added
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addvertex-step" target="_blank">Reference Documentation - AddVertex Step</a>
* @since 3.1.0-incubating
*/
@@ -1387,7 +1383,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
/**
* Adds a {@link Vertex} with a vertex label determined by a {@link Traversal}.
*
- * @return the traversal with the {@link AddVertexStep} added
+ * @return the traversal with the {@link AddVertexStepContract} added
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addvertex-step" target="_blank">Reference Documentation - AddVertex Step</a>
* @since 3.3.1
*/
@@ -1401,7 +1397,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* Adds a {@link Vertex}.
*
* @param vertexLabel the label of the {@link Vertex} to add
- * @return the traversal with the {@link AddVertexStep} added
+ * @return the traversal with the {@link AddVertexStepContract} added
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addvertex-step" target="_blank">Reference Documentation - AddVertex Step</a>
* @since 3.8.0
*/
@@ -1414,13 +1410,13 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
/**
* Adds a {@link Vertex} with a default vertex label.
*
- * @return the traversal with the {@link AddVertexStep} added
+ * @return the traversal with the {@link AddVertexStepContract} added
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addvertex-step" target="_blank">Reference Documentation - AddVertex Step</a>
* @since 3.1.0-incubating
*/
public default GraphTraversal<S, Vertex> addV() {
this.asAdmin().getBytecode().addStep(Symbols.addV);
- return this.asAdmin().addStep(new AddVertexStep<>(this.asAdmin(), (String) null));
+ return this.asAdmin().addStep(new AddVertexStepPlaceholder<>(this.asAdmin(), (String) null));
}
/**
@@ -1543,7 +1539,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* Adds an {@link Edge} with the specified edge label.
*
* @param edgeLabel the label of the newly added edge
- * @return the traversal with the {@link AddEdgeStep} added
+ * @return the traversal with the {@link AddEdgeStepContract} added
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - AddEdge Step</a>
* @since 3.1.0-incubating
*/
@@ -1556,7 +1552,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
/**
* Adds a {@link Edge} with an edge label determined by a {@link Traversal}.
*
- * @return the traversal with the {@link AddEdgeStep} added
+ * @return the traversal with the {@link AddEdgeStepContract} added
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - AddEdge Step</a>
* @since 3.3.1
*/
@@ -1570,7 +1566,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* Adds an {@link Edge} with the specified edge label.
*
* @param edgeLabel the label of the newly added edge
- * @return the traversal with the {@link AddEdgeStep} added
+ * @return the traversal with the {@link AddEdgeStepContract} added
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - AddEdge Step</a>
* @since 3.8.0
*/
@@ -1604,7 +1600,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* outgoing vertex of the newly added {@link Edge}.
*
* @param fromVertex the vertex for selecting the outgoing vertex
- * @return the traversal with the modified {@link AddEdgeStep}
+ * @return the traversal with the modified {@link AddEdgeStepContract}
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - From Step</a>
* @since 3.8.0
*/
@@ -1624,7 +1620,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* outgoing vertex of the newly added {@link Edge}.
*
* @param fromVertex the vertex for selecting the outgoing vertex
- * @return the traversal with the modified {@link AddEdgeStep}
+ * @return the traversal with the modified {@link AddEdgeStepContract}
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - From Step</a>
* @since 3.3.0
*/
@@ -1663,7 +1659,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* incoming vertex of the newly added {@link Edge}.
*
* @param toVertex the vertex for selecting the incoming vertex
- * @return the traversal with the modified {@link AddEdgeStep}
+ * @return the traversal with the modified {@link AddEdgeStepContract}
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - From Step</a>
* @since 3.8.0
*/
@@ -1683,7 +1679,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* incoming vertex of the newly added {@link Edge}.
*
* @param toVertex the traversal for selecting the incoming vertex
- * @return the traversal with the modified {@link AddEdgeStep}
+ * @return the traversal with the modified {@link AddEdgeStepContract}
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - From Step</a>
* @since 3.1.0-incubating
*/
@@ -1703,7 +1699,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* outgoing vertex of the newly added {@link Edge}.
*
* @param fromVertex the traversal for selecting the outgoing vertex
- * @return the traversal with the modified {@link AddEdgeStep}
+ * @return the traversal with the modified {@link AddEdgeStepContract}
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - From Step</a>
* @since 3.1.0-incubating
*/
@@ -1723,7 +1719,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* incoming vertex of the newly added {@link Edge}.
*
* @param toVertex the vertex for selecting the incoming vertex
- * @return the traversal with the modified {@link AddEdgeStep}
+ * @return the traversal with the modified {@link AddEdgeStepContract}
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - From Step</a>
* @since 3.3.0
*/
@@ -1751,7 +1747,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* outgoing vertex of the newly added {@link Edge}.
*
* @param fromVertex the vertex for selecting the outgoing vertex
- * @return the traversal with the modified {@link AddEdgeStep}
+ * @return the traversal with the modified {@link AddEdgeStepContract}
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#addedge-step" target="_blank">Reference Documentation - From Step</a>
* @since 3.3.0
*/
@@ -3804,9 +3800,9 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* {@link #property(Object, Object, Object...)} with the difference that the {@link VertexProperty.Cardinality}
* can be supplied.
* <p/>*
- * Generally speaking, this method will append an {@link AddPropertyStep} to the {@link Traversal} but when
- * possible, this method will attempt to fold key/value pairs into an {@link AddVertexStep}, {@link AddEdgeStep} or
- * {@link AddVertexStartStep}. This potential optimization can only happen if cardinality is not supplied
+ * Generally speaking, this method will append an {@link AddPropertyStepContract} to the {@link Traversal} but when
+ * possible, this method will attempt to fold key/value pairs into an {@link AddVertexStepContract} or {@link AddEdgeStepContract}.
+ * This potential optimization can only happen if cardinality is not supplied
* and when meta-properties are not included.
*
* @param cardinality the specified cardinality of the property where {@code null} will allow the {@link Graph}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddEdgeStepPlaceholder.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddEdgeStepPlaceholder.java
index a5d9c46600..2f4b022354 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddEdgeStepPlaceholder.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddEdgeStepPlaceholder.java
@@ -45,6 +45,11 @@ public abstract class AbstractAddEdgeStepPlaceholder<S> extends AbstractAddEleme
super(traversal, labelTraversal);
}
+ @Override
+ protected String getDefaultLabel() {
+ return Edge.DEFAULT_LABEL;
+ }
+
@Override
public void addTo(final Traversal.Admin<?, ?> toObject) {
addTraversal(toObject);
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddElementStepPlaceholder.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddElementStepPlaceholder.java
index 4083168269..012af45132 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddElementStepPlaceholder.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddElementStepPlaceholder.java
@@ -33,7 +33,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequire
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.T;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
import java.util.ArrayList;
import java.util.Collection;
@@ -42,38 +41,41 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
public abstract class AbstractAddElementStepPlaceholder<S, E extends Element, X extends Event> extends ScalarMapStep<S, E>
implements AddElementStepContract<S, E>, GValueHolder<S, E>, Writing<X> {
- protected Traversal.Admin<S, String> label;
+ protected Object label;
protected Map<Object, List<Object>> properties = new HashMap<>();
- protected Traversal.Admin<S, Object> elementId;
+ protected Object elementId;
protected Set<String> scopeKeys = new HashSet<>();
- public AbstractAddElementStepPlaceholder(final Traversal.Admin traversal, final String label) {
- this(traversal, label == null ? null : new ConstantTraversal<>(label));
+ protected AbstractAddElementStepPlaceholder(final Traversal.Admin traversal, final String label) {
+ super(traversal);
+ this.label = label == null ? this.getDefaultLabel() : label;
}
- public AbstractAddElementStepPlaceholder(final Traversal.Admin traversal, final GValue<String> label) {
- this(traversal.asAdmin(), label == null ? null : new GValueConstantTraversal<>(label));
+ protected AbstractAddElementStepPlaceholder(final Traversal.Admin traversal, final GValue<String> label) {
+ super(traversal);
+ this.label = label == null ? this.getDefaultLabel() : label;
+ if (label.isVariable()) {
+ traversal.getGValueManager().register(label);
+ }
}
- public AbstractAddElementStepPlaceholder(final Traversal.Admin traversal, final Traversal.Admin<S,String> labelTraversal) {
+ protected AbstractAddElementStepPlaceholder(final Traversal.Admin traversal, final Traversal.Admin<S,String> labelTraversal) {
super(traversal);
- if (labelTraversal == null) {
- throw new IllegalArgumentException("The label provided must not be null");
- }
- this.label = labelTraversal;
+ this.label = labelTraversal == null ? this.getDefaultLabel() : labelTraversal;
if (labelTraversal instanceof GValueConstantTraversal) {
traversal.getGValueManager().register(((GValueConstantTraversal<S, String>) labelTraversal).getGValue());
}
addTraversal(labelTraversal);
}
+ protected abstract String getDefaultLabel();
+
@Override
public Set<String> getScopeKeys() {
return Collections.unmodifiableSet(scopeKeys);
@@ -97,11 +99,11 @@ public abstract class AbstractAddElementStepPlaceholder<S, E extends Element, X
}
}
}
- if (label != null) {
- childTraversals.add(label);
+ if (label != null && label instanceof Traversal) {
+ childTraversals.add(((Traversal<?, ?>) label).asAdmin());
}
- if (elementId != null) {
- childTraversals.add(elementId);
+ if (elementId != null && elementId instanceof Traversal) {
+ childTraversals.add(((Traversal<?, ?>) elementId).asAdmin());
}
return childTraversals;
}
@@ -128,11 +130,14 @@ public abstract class AbstractAddElementStepPlaceholder<S, E extends Element, X
if (label != null) {
hash ^= label.hashCode();
}
+ if (elementId != null) {
+ hash ^= elementId.hashCode();
+ }
if (properties != null) {
for (Map.Entry<Object, List<Object>> entry : properties.entrySet()) {
hash ^= Objects.hashCode(entry.getKey());
hash ^= Objects.hashCode(entry.getValue());
- };
+ }
}
return hash;
}
@@ -144,19 +149,15 @@ public abstract class AbstractAddElementStepPlaceholder<S, E extends Element, X
}
}
if (elementId != null) {
- if (elementId instanceof GValueConstantTraversal || elementId instanceof ConstantTraversal) {
- step.setElementId(this.elementId.next());
- } else {
- step.setElementId(this.elementId);
- }
+ step.setElementId(elementId instanceof GValue ? ((GValue<?>) elementId).get() : elementId);
}
TraversalHelper.copyLabels(this, step, false);
}
@Override
public boolean isParameterized() {
- if (label instanceof GValueConstantTraversal && ((GValueConstantTraversal<S, String>) label).isParameterized() ||
- (elementId instanceof GValueConstantTraversal && ((GValueConstantTraversal<S, Object>) elementId).isParameterized())) {
+ if (label instanceof GValue && ((GValue<?>) label).isVariable() ||
+ (elementId instanceof GValue && ((GValue<?>) elementId).isVariable())) {
return true;
}
for (List<Object> list : properties.values()) {
@@ -169,35 +170,33 @@ public abstract class AbstractAddElementStepPlaceholder<S, E extends Element, X
@Override
public Object getLabel() {
- if (label instanceof GValueConstantTraversal) {
- traversal.getGValueManager().pinVariable(((GValueConstantTraversal<?, ?>) label).getGValue().getName());
- return ((GValueConstantTraversal<?, ?>) label).getGValue().get();
- }
- if (label instanceof ConstantTraversal) {
- return label.next();
+ if (label instanceof GValue) {
+ traversal.getGValueManager().pinVariable(((GValue<?>) label).getName());
+ return ((GValue<?>) label).get();
}
return label;
}
@Override
public Object getLabelWithGValue() {
- if (label instanceof GValueConstantTraversal) {
- return ((GValueConstantTraversal<S, String>) label).getGValue();
- }
- return getLabel(); //Don't need to worry about pinning as GValue case is covered above
+ return label;
}
- private void setLabel(Object label) {// TODO should this be public and added to step interface?
- if (getLabelWithGValue().equals(Vertex.DEFAULT_LABEL)) {
+ @Override
+ public void setLabel(Object label) {
+ if (this.label.equals(this.getDefaultLabel())) {
if (label instanceof Traversal) {
this.label = ((Traversal<S, String>) label).asAdmin();
- } else {
- this.label = label instanceof GValue ? new GValueConstantTraversal<>((GValue) label) : new ConstantTraversal<>((String) label);
- }
- if (label instanceof GValue) {
+ this.integrateChild((Traversal.Admin<?, ?>) this.label);
+ } else if (label instanceof GValue) {
+ this.label = label;
traversal.getGValueManager().register((GValue<?>) label);
+ } else {
+ this.label = label;
}
- this.integrateChild(this.label);
+ } else {
+ throw new IllegalArgumentException(String.format("Element T.label has already been set to [%s] and cannot be overridden with [%s]",
+ this.label, label));
}
}
@@ -258,25 +257,16 @@ public abstract class AbstractAddElementStepPlaceholder<S, E extends Element, X
@Override
public Object getElementId() {
- if (elementId == null) {
- return null;
- }
- if (elementId instanceof GValueConstantTraversal) {
- this.traversal.getGValueManager().pinVariable(((GValueConstantTraversal<S, Object>) elementId).getGValue().getName());
- return ((GValueConstantTraversal<S, Object>) elementId).getGValue().get();
- }
- if (elementId instanceof ConstantTraversal) {
- return elementId.next();
+ if (elementId instanceof GValue) {
+ this.traversal.getGValueManager().pinVariable(((GValue<?>) elementId).getName());
+ return ((GValue<?>) elementId).get();
}
return elementId;
}
@Override
public Object getElementIdWithGValue() {
- if (elementId instanceof GValueConstantTraversal) {
- return ((GValueConstantTraversal<S, Object>) elementId).getGValue();
- }
- return getElementId(); //Don't need to worry about pinning as GValue case is covered above
+ return elementId;
}
@Override
@@ -290,24 +280,28 @@ public abstract class AbstractAddElementStepPlaceholder<S, E extends Element, X
@Override
public void setElementId(Object elementId) {
+ if (this.elementId != null) {
+ throw new IllegalArgumentException(String.format("Element T.id has already been set to [%s] and cannot be overridden with [%s]",
+ this.elementId, elementId));
+ }
if (elementId instanceof Traversal) {
this.elementId = ((Traversal<S, Object>) elementId).asAdmin();
- } else {
- this.elementId = elementId instanceof GValue ? new GValueConstantTraversal<>((GValue) elementId) : new ConstantTraversal<>(elementId);
- }
- if (elementId instanceof GValue) {
+ this.integrateChild((Traversal.Admin<?, ?>) this.elementId);
+ } else if (elementId instanceof GValue) {
traversal.getGValueManager().register((GValue<?>) elementId);
+ this.elementId = elementId;
+ } else {
+ this.elementId = elementId;
}
- this.integrateChild(this.elementId);
}
@Override
public void updateVariable(String name, Object value) {
- if (label instanceof GValueConstantTraversal) {
- ((GValueConstantTraversal<S, String>) label).updateVariable(name, value);
+ if (label instanceof GValue && name.equals(((GValue<?>) label).getName())) {
+ label = GValue.of(name, value);
}
- if (elementId instanceof GValueConstantTraversal) {
- ((GValueConstantTraversal<S, Object>) elementId).updateVariable(name, value);
+ if (elementId instanceof GValue && name.equals(((GValue<?>) elementId).getName())) {
+ elementId = GValue.of(name, value);
}
for (final Map.Entry<Object, List<Object>> entry : properties.entrySet()) {
for (final Object propertyVal : entry.getValue()) {
@@ -321,11 +315,11 @@ public abstract class AbstractAddElementStepPlaceholder<S, E extends Element, X
@Override
public Collection<GValue<?>> getGValues() {
Set<GValue<?>> gValues = GValueHelper.getGValuesFromProperties(properties);
- if (label instanceof GValueConstantTraversal && ((GValueConstantTraversal<S, String>) label).getGValue().isVariable()) {
- gValues.add(((GValueConstantTraversal<S, String>) label).getGValue());
+ if (label instanceof GValue && ((GValue<?>) label).isVariable()) {
+ gValues.add((GValue<?>) label);
}
- if (elementId instanceof GValueConstantTraversal && ((GValueConstantTraversal<S, Object>) elementId).isParameterized()) {
- gValues.add(((GValueConstantTraversal<S, Object>) elementId).getGValue());
+ if (elementId instanceof GValue && ((GValue<?>) elementId).isVariable()) {
+ gValues.add((GValue<?>) elementId);
}
return gValues;
}
@@ -339,10 +333,24 @@ public abstract class AbstractAddElementStepPlaceholder<S, E extends Element, X
public AbstractAddElementStepPlaceholder<S, E, X> clone() {
final AbstractAddElementStepPlaceholder<S, E, X> clone = (AbstractAddElementStepPlaceholder) super.clone();
if (label != null) {
- clone.label = label.clone();
+ // Attempt to deep clone label for Traversal and GValue.
+ if (this.label instanceof Traversal) {
+ clone.label = ((Traversal<?, ?>) this.label).asAdmin().clone();
+ } else if (this.label instanceof GValue) {
+ clone.label = ((GValue<?>) this.label).clone();
+ } else {
+ clone.label = this.label;
+ }
}
if (elementId != null) {
- clone.elementId = elementId.clone();
+ // Attempt to deep clone elementId for Traversal and GValue.
+ if (this.elementId instanceof Traversal) {
+ clone.elementId = ((Traversal<?, ?>) this.elementId).asAdmin().clone();
+ } else if (this.elementId instanceof GValue) {
+ clone.elementId = ((GValue<?>) this.elementId).clone();
+ } else {
+ clone.elementId = this.elementId;
+ }
}
// deep clone properties
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddVertexStepPlaceholder.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddVertexStepPlaceholder.java
index 451dc4b1b9..6413b816dd 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddVertexStepPlaceholder.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddVertexStepPlaceholder.java
@@ -19,8 +19,6 @@
package org.apache.tinkerpop.gremlin.process.traversal.step.map;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.process.traversal.lambda.ConstantTraversal;
-import org.apache.tinkerpop.gremlin.process.traversal.lambda.GValueConstantTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.step.GValue;
import org.apache.tinkerpop.gremlin.process.traversal.step.GValueHolder;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.event.Event;
@@ -31,22 +29,26 @@ public abstract class AbstractAddVertexStepPlaceholder<S> extends AbstractAddEle
private boolean userProvidedLabel;
- public AbstractAddVertexStepPlaceholder(final Traversal.Admin traversal, final String label) {
- super(traversal, label == null ? Vertex.DEFAULT_LABEL : label);
+ protected AbstractAddVertexStepPlaceholder(final Traversal.Admin traversal, final String label) {
+ super(traversal, label);
userProvidedLabel = label != null;
}
- public AbstractAddVertexStepPlaceholder(final Traversal.Admin traversal, final GValue<String> label) {
- super(traversal, label == null ? GValue.of(Vertex.DEFAULT_LABEL) : label);
+ protected AbstractAddVertexStepPlaceholder(final Traversal.Admin traversal, final GValue<String> label) {
+ super(traversal, label);
userProvidedLabel = label != null;
}
- public AbstractAddVertexStepPlaceholder(final Traversal.Admin traversal, final Traversal.Admin<S,String> vertexLabelTraversal) {
- super(traversal, vertexLabelTraversal == null ?
- new ConstantTraversal<>(Vertex.DEFAULT_LABEL) : vertexLabelTraversal);
+ protected AbstractAddVertexStepPlaceholder(final Traversal.Admin traversal, final Traversal.Admin<S,String> vertexLabelTraversal) {
+ super(traversal, vertexLabelTraversal);
userProvidedLabel = vertexLabelTraversal != null;
}
+ @Override
+ protected String getDefaultLabel() {
+ return Vertex.DEFAULT_LABEL;
+ }
+
@Override
public boolean hasUserProvidedLabel() {
return userProvidedLabel;
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStartStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStartStep.java
index 2fe2827659..caa723730d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStartStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStartStep.java
@@ -208,6 +208,11 @@ public class AddEdgeStartStep extends AbstractStep<Edge, Edge>
return label;
}
+ @Override
+ public void setLabel(Object label) {
+ this.configure(T.label, label);
+ }
+
@Override
public Object getFrom() {
return getAdjacentVertex(this.parameters, FROM);
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStartStepPlaceholder.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStartStepPlaceholder.java
index 85912cdf65..edcd641a49 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStartStepPlaceholder.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStartStepPlaceholder.java
@@ -42,7 +42,14 @@ public class AddEdgeStartStepPlaceholder extends AbstractAddEdgeStepPlaceholder<
@Override
public AddEdgeStartStep asConcreteStep() {
- AddEdgeStartStep step = new AddEdgeStartStep(traversal, label instanceof GValueConstantTraversal ? ((GValueConstantTraversal<?, String>) label).getConstantTraversal() : label);
+ AddEdgeStartStep step;
+ if (label instanceof Traversal) {
+ step = new AddEdgeStartStep(traversal, ((Traversal<?, String>) label).asAdmin());
+ } else if (label instanceof GValue) {
+ step = new AddEdgeStartStep(traversal, ((GValue<String>) label).get());
+ } else {
+ step = new AddEdgeStartStep(traversal, (String) label);
+ }
super.configureConcreteStep(step);
if (from != null) {
step.addFrom(from instanceof GValueConstantTraversal ? ((GValueConstantTraversal<?, String>) from).getConstantTraversal() : from);
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
index 77d6dfcffa..e96bd99c28 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStep.java
@@ -180,6 +180,11 @@ public class AddEdgeStep<S> extends ScalarMapStep<S, Edge>
return label;
}
+ @Override
+ public void setLabel(Object label) {
+ this.configure(T.label, label);
+ }
+
@Override
public void addProperty(Object key, Object value) {
configure(key, value);
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStepPlaceholder.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStepPlaceholder.java
index b7d3b57b45..e4fd203c69 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStepPlaceholder.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddEdgeStepPlaceholder.java
@@ -41,7 +41,14 @@ public class AddEdgeStepPlaceholder<S> extends AbstractAddEdgeStepPlaceholder<S>
@Override
public AddEdgeStep<S> asConcreteStep() {
- AddEdgeStep<S> step = new AddEdgeStep<>(traversal, label instanceof GValueConstantTraversal ? ((GValueConstantTraversal<S, String>) label).getConstantTraversal() : label);
+ AddEdgeStep<S> step;
+ if (label instanceof Traversal) {
+ step = new AddEdgeStep<>(traversal, ((Traversal<S, String>) label).asAdmin());
+ } else if (label instanceof GValue) {
+ step = new AddEdgeStep<>(traversal, ((GValue<String>) label).get());
+ } else {
+ step = new AddEdgeStep<>(traversal, (String) label);
+ }
super.configureConcreteStep(step);
if (from != null) {
step.addFrom(from instanceof GValueConstantTraversal ? ((GValueConstantTraversal<S, String>) from).getConstantTraversal() : from);
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddElementStepContract.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddElementStepContract.java
index 2ed91d5626..893a5607a0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddElementStepContract.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddElementStepContract.java
@@ -33,6 +33,8 @@ public interface AddElementStepContract<S, E> extends Step<S, E>, PropertiesHold
return getLabel();
}
+ void setLabel(Object label);
+
Object getElementId();
default Object getElementIdWithGValue() {
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStartStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStartStep.java
index 053b9ff911..5cdf988ba3 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStartStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStartStep.java
@@ -175,6 +175,11 @@ public class AddVertexStartStep extends AbstractStep<Vertex, Vertex> implements
return label;
}
+ @Override
+ public void setLabel(Object label) {
+ this.configure(T.label, label);
+ }
+
@Override
public Map<Object, List<Object>> getProperties() {
return Collections.unmodifiableMap(parameters.getRaw());
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStartStepPlaceholder.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStartStepPlaceholder.java
index 8a95182a13..08e0fa9bb6 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStartStepPlaceholder.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStartStepPlaceholder.java
@@ -20,7 +20,6 @@ package org.apache.tinkerpop.gremlin.process.traversal.step.map;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.lambda.ConstantTraversal;
-import org.apache.tinkerpop.gremlin.process.traversal.lambda.GValueConstantTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.step.GValue;
import org.apache.tinkerpop.gremlin.process.traversal.step.GValueHolder;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -43,7 +42,14 @@ public class AddVertexStartStepPlaceholder extends AbstractAddVertexStepPlacehol
@Override
public AddVertexStartStep asConcreteStep() {
- AddVertexStartStep step = new AddVertexStartStep(traversal, label instanceof GValueConstantTraversal ? ((GValueConstantTraversal<?, String>) label).getConstantTraversal() : label);
+ AddVertexStartStep step;
+ if (label instanceof Traversal) {
+ step = new AddVertexStartStep(traversal, ((Traversal<?, String>) label).asAdmin());
+ } else if (label instanceof GValue) {
+ step = new AddVertexStartStep(traversal, ((GValue<String>) label).get());
+ } else {
+ step = new AddVertexStartStep(traversal, (String) label);
+ }
super.configureConcreteStep(step);
return step;
}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStep.java
index baead68ac1..93e6701700 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStep.java
@@ -161,6 +161,11 @@ public class AddVertexStep<S> extends ScalarMapStep<S, Vertex> implements AddVer
return label;
}
+ @Override
+ public void setLabel(Object label) {
+ this.configure(T.label, label);
+ }
+
@Override
public Map<Object, List<Object>> getProperties() {
return Collections.unmodifiableMap(parameters.getRaw());
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStepPlaceholder.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStepPlaceholder.java
index 2147c1010a..173edd8c5f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStepPlaceholder.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStepPlaceholder.java
@@ -38,7 +38,14 @@ public class AddVertexStepPlaceholder<S> extends AbstractAddVertexStepPlaceholde
@Override
public AddVertexStep<S> asConcreteStep() {
- AddVertexStep<S> step = new AddVertexStep<>(traversal, label instanceof GValueConstantTraversal ? ((GValueConstantTraversal<S, String>) label).getConstantTraversal() : label);
+ AddVertexStep<S> step;
+ if (label instanceof Traversal) {
+ step = new AddVertexStep<>(traversal, ((Traversal<S, String>) label).asAdmin());
+ } else if (label instanceof GValue) {
+ step = new AddVertexStep<>(traversal, ((GValue<String>) label).get());
+ } else {
+ step = new AddVertexStep<>(traversal, (String) label);
+ }
super.configureConcreteStep(step);
return step;
}
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/TraversalParentTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/TraversalParentTest.java
index f209b11ac5..c422f18b81 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/TraversalParentTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/TraversalParentTest.java
@@ -157,7 +157,7 @@ public class TraversalParentTest {
{AddVertexStepContract.class,
g.addV("label").property("name", __.constant("cole")),
List.of(),
- List.of(__.constant("cole"), new ConstantTraversal<>("label")),
+ List.of(__.constant("cole")),
null, null
},
{AddVertexStepContract.class,
@@ -175,19 +175,19 @@ public class TraversalParentTest {
{AddVertexStepContract.class,
g.addV(GValue.of("l", "label")).property("name", GValue.of("name", "cole")),
List.of(),
- List.of(new ConstantTraversal<>("label")), // Property is not stored as a child traversal in this case
+ List.of(), // Property is not stored as a child traversal in this case
null, null
},
{AddVertexStepContract.class,
g.addV("label").property(__.constant("name"), __.constant("cole")),
List.of(),
- List.of(__.constant("name"), __.constant("cole"), new ConstantTraversal<>("label")),
+ List.of(__.constant("name"), __.constant("cole")),
null, null
},
{AddVertexStepContract.class,
g.inject(1).addV("label").property("name", __.constant("cole")),
List.of(),
- List.of(__.constant("cole"), new ConstantTraversal<>("label")),
+ List.of(__.constant("cole")),
null, null
},
{AddVertexStepContract.class,
@@ -199,19 +199,19 @@ public class TraversalParentTest {
{AddVertexStepContract.class,
g.inject(1).addV(GValue.of("l", "label")).property("name", GValue.of("name", "cole")),
List.of(),
- List.of(new ConstantTraversal<>("label")), // Property is not stored as a child traversal in this case
+ List.of(), // Property is not stored as a child traversal in this case
null, null
},
{AddVertexStepContract.class,
g.inject(1).addV("label").property(__.constant("name"), __.constant("cole")),
List.of(),
- List.of(__.constant("name"), __.constant("cole"), new ConstantTraversal<>("label")),
+ List.of(__.constant("name"), __.constant("cole")),
null, null
},
{AddEdgeStepContract.class,
g.addE("label").from(1).to(2).property("name", __.constant("cole")),
List.of(),
- List.of(__.constant("cole"), new ConstantTraversal<>("label"), __.constant(1), __.constant(2)),
+ List.of(__.constant("cole"), __.constant(1), __.constant(2)),
null, null
},
{AddEdgeStepContract.class,
@@ -219,49 +219,49 @@ public class TraversalParentTest {
.property("name", __.constant("cole"))
.property(T.id, __.constant(5)),
List.of(),
- List.of(__.constant("cole"), new ConstantTraversal<>("label"), __.V(1), __.V(2), __.constant(5)),
+ List.of(__.constant("cole"), __.V(1), __.V(2), __.constant(5)),
null, null
},
{AddEdgeStepContract.class,
g.addE("label").from(__.V(1)).to(__.V(2)).property("name", __.constant("cole")),
List.of(),
- List.of(__.constant("cole"), new ConstantTraversal<>("label"), __.V(1), __.V(2)),
+ List.of(__.constant("cole"), __.V(1), __.V(2)),
null, null
},
{AddEdgeStepContract.class,
g.addE(GValue.of("l", "label")).from(GValue.of("from", 1)).to(GValue.of("to", 2)).property("name", GValue.of("name", "cole")),
List.of(),
- List.of(new ConstantTraversal<>("label"), new ConstantTraversal<>(1), new ConstantTraversal<>(2)),
+ List.of(new ConstantTraversal<>(1), new ConstantTraversal<>(2)),
null, null
},
{AddEdgeStepContract.class,
g.addE("label").from(1).to(2).property(__.constant("name"), __.constant("cole")),
List.of(),
- List.of(__.constant("name"), __.constant("cole"), new ConstantTraversal<>("label"), __.constant(1), __.constant(2)),
+ List.of(__.constant("name"), __.constant("cole"), __.constant(1), __.constant(2)),
null, null
},
{AddEdgeStepContract.class,
g.inject(1).addE("label").from(1).to(2).property("name", __.constant("cole")),
List.of(),
- List.of(__.constant("cole"), new ConstantTraversal<>("label"), __.constant(1), __.constant(2)),
+ List.of(__.constant("cole"), __.constant(1), __.constant(2)),
null, null
},
{AddEdgeStepContract.class,
g.inject(1).addE("label").from(__.V(1)).to(__.V(2)).property("name", __.constant("cole")),
List.of(),
- List.of(__.constant("cole"), new ConstantTraversal<>("label"), __.V(1), __.V(2)),
+ List.of(__.constant("cole"), __.V(1), __.V(2)),
null, null
},
{AddEdgeStepContract.class,
g.inject(1).addE(GValue.of("l", "label")).from(GValue.of("from", 1)).to(GValue.of("to", 2)).property("name", GValue.of("name", "cole")),
List.of(),
- List.of(new ConstantTraversal<>("label"), new ConstantTraversal<>(1), new ConstantTraversal<>(2)),
+ List.of(new ConstantTraversal<>(1), new ConstantTraversal<>(2)),
null, null
},
{AddEdgeStepContract.class,
g.inject(1).addE("label").from(1).to(2).property(__.constant("name"), __.constant("cole")),
List.of(),
- List.of(__.constant("name"), __.constant("cole"), new ConstantTraversal<>("label"), __.constant(1), __.constant(2)),
+ List.of(__.constant("name"), __.constant("cole"), __.constant(1), __.constant(2)),
null, null
},
{CallStepContract.class,
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/ReservedKeysVerificationStrategyTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/ReservedKeysVerificationStrategyTest.java
index fa085026b9..5cdcf8badd 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/ReservedKeysVerificationStrategyTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/ReservedKeysVerificationStrategyTest.java
@@ -76,7 +76,6 @@ public class ReservedKeysVerificationStrategyTest {
{__.addV().property("id", 123), false},
{__.addE("knows").property("id", 123), false},
{__.addV().property(T.id, 123), true},
- {__.addE("knows").property(T.label, "blah"), true},
{__.addV().property("label", "xyz"), false},
{__.addE("knows").property("id", "xyz"), false},
{__.addV().property("x", "xyz", "label", "xxx"), false},