kenhuuu commented on code in PR #3241:
URL: https://github.com/apache/tinkerpop/pull/3241#discussion_r2437315993


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/RangeGlobalStep.java:
##########
@@ -55,40 +64,72 @@ public RangeGlobalStep(final Traversal.Admin traversal, 
final long low, final lo
     protected boolean filter(final Traverser.Admin<S> traverser) {
         if (this.bypass) return true;
 
-        if (this.high != -1 && this.counter.get() >= this.high) {
+        final String counterKey = getCounterKey(traverser);
+        final AtomicLong counter = counters.computeIfAbsent(counterKey, k -> 
new AtomicLong(0L));
+
+        if (this.high != -1 && counter.get() >= this.high) {
+            if (this.getTraversal().getParent() instanceof RepeatStep) {
+                return false;
+            }
             throw FastNoSuchElementException.instance();
         }
 
         long avail = traverser.bulk();
-        if (this.counter.get() + avail <= this.low) {
+        if (counter.get() + avail <= this.low) {
             // Will not surpass the low w/ this traverser. Skip and filter the 
whole thing.
-            this.counter.getAndAdd(avail);
+            counter.getAndAdd(avail);
             return false;
         }
 
         // Skip for the low and trim for the high. Both can happen at once.
 
         long toSkip = 0;
-        if (this.counter.get() < this.low) {
-            toSkip = this.low - this.counter.get();
+        if (counter.get() < this.low) {
+            toSkip = this.low - counter.get();
         }
 
         long toTrim = 0;
-        if (this.high != -1 && this.counter.get() + avail >= this.high) {
-            toTrim = this.counter.get() + avail - this.high;
+        if (this.high != -1 && counter.get() + avail >= this.high) {
+            toTrim = counter.get() + avail - this.high;
         }
 
         long toEmit = avail - toSkip - toTrim;
-        this.counter.getAndAdd(toSkip + toEmit);
+        counter.getAndAdd(toSkip + toEmit);
         traverser.setBulk(toEmit);
 
         return true;
     }
 
+    private String getCounterKey(Traverser.Admin<S> traverser) {

Review Comment:
   Nit: check for `final`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to