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/05/14 17:05:37 UTC

(tinkerpop) branch GValueManager3.8 updated: Squash of WIP GValueManager commits

This is an automated email from the ASF dual-hosted git repository.

colegreer pushed a commit to branch GValueManager3.8
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/GValueManager3.8 by this push:
     new 35d30efc7e Squash of WIP GValueManager commits
35d30efc7e is described below

commit 35d30efc7e25cf4efcd82df90a7cebd743f1489c
Author: Cole-Greer <Co...@improving.com>
AuthorDate: Wed May 14 10:04:29 2025 -0700

    Squash of WIP GValueManager commits
---
 .../gremlin/process/traversal/GValueManager.java   | 28 ++++++++++++++++++++++
 .../traversal/dsl/graph/GraphTraversal.java        |  2 +-
 .../strategy/decoration/SeedStrategy.java          |  5 ++++
 .../strategy/optimization/EarlyLimitStrategy.java  | 13 ++++++++++
 .../optimization/FilterRankingStrategy.java        |  5 ++++
 .../optimization/IncidentToAdjacentStrategy.java   |  5 ++++
 .../process/traversal/util/DefaultTraversal.java   |  1 +
 .../process/traversal/util/TraversalHelper.java    |  1 +
 8 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GValueManager.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GValueManager.java
index 3f982b0106..2903f174ba 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GValueManager.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GValueManager.java
@@ -185,8 +185,36 @@ public class GValueManager implements Serializable {
         return this.stepRegistry.containsKey(step) || this.predicateRegistry.containsKey(step);
     }
 
+
+    /**
+     * Delete all data
+     */
     public void reset() {
         stepRegistry.clear();
         gValueRegistry.clear();
     }
+
+    /**
+     * Delete all data for all GValues associated with a single Step
+     * @param step
+     */
+    public void reset(Step step) {
+        StepContract contract = stepRegistry.remove(step);
+
+        if (contract != null) {
+            if(contract instanceof RangeContract){
+                removeFromGValueRegistry(((RangeContract<GValue<?>>) contract).getHighRange());
+                removeFromGValueRegistry(((RangeContract<GValue<?>>) contract).getLowRange());
+            }// TODO else if chain for all contract types
+        }
+
+    }
+
+    private void removeFromGValueRegistry(GValue<?> gValue) {
+        if (gValue == null || gValue.getName() == null) {
+            return;
+        }
+        gValueRegistry.remove(gValue.getName());
+        //TODO:: Find if any steps are using same GValue and remove.
+    }
 }
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 e0584145b7..5c9cd635d4 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
@@ -577,7 +577,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
         this.asAdmin().getBytecode().addStep(GraphTraversal.Symbols.both, edgeLabels);
         VertexStep<Vertex> step = new VertexStep<>(this.asAdmin(), Vertex.class, Direction.BOTH, Arrays.stream(GValue.resolveToValues(edgeLabels)).toArray(String[]::new));
 
-        this.asAdmin().getGValueManager().register(step, new DefaultEdgeLabelContract<GValue<String>>(edgeLabels));
+        this.asAdmin().getGValueManager().register(step, new DefaultEdgeLabelContract<>(edgeLabels));
 
         return this.asAdmin().addStep(step);
     }
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SeedStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SeedStrategy.java
index 63ed186838..b5c8db3c70 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SeedStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SeedStrategy.java
@@ -99,4 +99,9 @@ public class SeedStrategy extends AbstractTraversalStrategy<TraversalStrategy.De
             return new SeedStrategy(seed);
         }
     }
+
+    @Override
+    public void updateGValue(Traversal.Admin<?, ?> traversal) {
+        // Do nothing, strategy is 100% GValue safe
+    }
 }
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/EarlyLimitStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/EarlyLimitStrategy.java
index cffff8c9ad..9f43bdb1d7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/EarlyLimitStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/EarlyLimitStrategy.java
@@ -144,4 +144,17 @@ public final class EarlyLimitStrategy
     public static EarlyLimitStrategy instance() {
         return INSTANCE;
     }
+
+    @Override
+    public void updateGValue(final Traversal.Admin<?, ?> traversal) {
+        // EarlyLimitStrategy makes optimizations according to the current high and low values in RangeGlobalStep.
+        // These GValues must be cleared as these optimizations are not generalizable for any high/low values.
+        // Other steps GValues may remain intact as this strategy does not operate on them.
+
+        for (final Step step : traversal.getSteps()) {
+            if (step instanceof RangeGlobalStep) {
+                traversal.getGValueManager().reset(step);
+            }
+        }
+    }
 }
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategy.java
index 96630be526..083d62e870 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategy.java
@@ -311,4 +311,9 @@ public final class FilterRankingStrategy extends AbstractTraversalStrategy<Trave
         }
         processingStack.push(childStep);
     }
+
+    @Override
+    public void updateGValue(Traversal.Admin<?, ?> traversal) {
+        // Do nothing, strategy is 100% GValue safe as it only relocates steps based on their class, it does not create new steps, nor does it make decisions based on step values
+    }
 }
\ No newline at end of file
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
index 42f5341831..8455c2515f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
@@ -161,4 +161,9 @@ public final class IncidentToAdjacentStrategy extends AbstractTraversalStrategy<
     public Set<Class<? extends OptimizationStrategy>> applyPost() {
         return Collections.singleton(PathRetractionStrategy.class);
     }
+
+    @Override
+    public void updateGValue(Traversal.Admin<?, ?> traversal) {
+        // Do nothing, strategy is 100% GValue safe as GValue state is copied to newly created steps
+    }
 }
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
index ae7c1b7120..db5725f50f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
@@ -138,6 +138,7 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S, E> {
             while (strategyIterator.hasNext()) {
                 final TraversalStrategy<?> strategy = strategyIterator.next();
                 TraversalHelper.applyTraversalRecursively(strategy::apply, this);
+                TraversalHelper.applyTraversalRecursively(strategy::updateGValue, this);
             }
         }
 
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
index ff5543184b..ac7b95059a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
@@ -769,6 +769,7 @@ public final class TraversalHelper {
         parentTraversal.getGraph().ifPresent(childTraversal::setGraph);
         for (final TraversalStrategy<?> strategy : parentTraversal.getStrategies()) {
             strategy.apply(childTraversal);
+            strategy.updateGValue(childTraversal);
             if (null != stopAfterStrategy && stopAfterStrategy.isInstance(strategy))
                 break;
         }