tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject [05/19] incubator-tinkerpop git commit: GroupSideEffectStep hack that has been here since 3.0 is now gutted. There is a FinalGet iinterface that we have used for reducing barriers -- however, Im going to promote it to a util/ object. Next up, get by('nam
Date Wed, 07 Oct 2015 21:14:09 GMT
GroupSideEffectStep hack that has been here since 3.0 is now gutted. There is a FinalGet iinterface
that we have used for reducing barriers -- however, Im going to promote it to a util/ object.
Next up, get by('name') working so its not by(values('name').fold()).


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/da2477b7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/da2477b7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/da2477b7

Branch: refs/heads/master
Commit: da2477b7b1688ebf36852894cdd53f223a304f00
Parents: e8a13f5
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Mon Oct 5 15:17:34 2015 -0600
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Mon Oct 5 15:17:34 2015 -0600

----------------------------------------------------------------------
 .../step/sideEffect/GroupSideEffectStep.java    | 42 ++++++++++++++++----
 .../step/sideEffect/SideEffectCapStep.java      | 19 ++++++---
 2 files changed, 48 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/da2477b7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroupSideEffectStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroupSideEffectStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroupSideEffectStep.java
index 0f00b94..7f90db7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroupSideEffectStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroupSideEffectStep.java
@@ -33,6 +33,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.SideEffectCapable;
 import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.BarrierStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMatrix;
@@ -42,6 +43,7 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 import org.apache.tinkerpop.gremlin.util.function.HashMapSupplier;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -65,7 +67,8 @@ public final class GroupSideEffectStep<S, K, V> extends SideEffectStep<S>
implem
     public GroupSideEffectStep(final Traversal.Admin traversal, final String sideEffectKey)
{
         super(traversal);
         this.sideEffectKey = sideEffectKey;
-        this.traversal.asAdmin().getSideEffects().registerSupplierIfAbsent(this.sideEffectKey,
HashMapSupplier.instance());
+        final FinalGroupMap<S, K, V> finalGroupMap = new FinalGroupMap<>(new
HashMap<>());
+        this.traversal.asAdmin().getSideEffects().registerSupplierIfAbsent(this.sideEffectKey,
() -> finalGroupMap); // HashMapSupplier.instance());
     }
 
     @Override
@@ -80,7 +83,8 @@ public final class GroupSideEffectStep<S, K, V> extends SideEffectStep<S>
implem
             }
             values.add(traverser);
         } else {
-            final Map<K, Traversal.Admin<S, V>> groupMap = traverser.sideEffects(this.sideEffectKey);
// for nested traversals and not !starts.hasNext()
+            final FinalGroupMap<S, K, V> finalGroupMap = traverser.sideEffects(this.sideEffectKey);
// for nested traversals and not !starts.hasNext()
+            final Map<K, Traversal.Admin<S, V>> groupMap = finalGroupMap.get();
             final K key = TraversalUtil.applyNullable(traverser, this.keyTraversal);
             Traversal.Admin<S, V> traversal = groupMap.get(key);
             if (null == traversal) {
@@ -91,11 +95,6 @@ public final class GroupSideEffectStep<S, K, V> extends SideEffectStep<S>
implem
             splitTraverser.setBulk(1l);
             traversal.addStart(splitTraverser);
             TraversalHelper.getStepsOfClass(BarrierStep.class, traversal).stream().findFirst().ifPresent(BarrierStep::processAllStarts);
-            if (!this.starts.hasNext()) {
-                final Map<K, V> reduceMap = new HashMap<>();
-                groupMap.forEach((k, t) -> reduceMap.put(k, t.next()));
-                traverser.sideEffects(this.sideEffectKey, reduceMap);
-            }
         }
     }
 
@@ -107,6 +106,8 @@ public final class GroupSideEffectStep<S, K, V> extends SideEffectStep<S>
implem
     @Override
     public void onEngine(final TraversalEngine traversalEngine) {
         this.onGraphComputer = traversalEngine.isComputer();
+        if (this.onGraphComputer)
+            this.traversal.asAdmin().getSideEffects().registerSupplier(this.sideEffectKey,
HashMapSupplier.instance());
     }
 
     @Override
@@ -167,6 +168,30 @@ public final class GroupSideEffectStep<S, K, V> extends SideEffectStep<S>
implem
 
     ///////////
 
+    public static class FinalGroupMap<S, K, V> implements ReducingBarrierStep.FinalGet<Map<K,
V>>, Serializable {
+
+        private final Map<K, Traversal.Admin<S, V>> mapTraversal;
+
+        public FinalGroupMap(final Map<K, Traversal.Admin<S, V>> mapTraversal)
{
+            this.mapTraversal = mapTraversal;
+        }
+
+        public Map<K, Traversal.Admin<S, V>> get() {
+            return this.mapTraversal;
+        }
+
+        @Override
+        public Map<K, V> getFinal() {
+            final Map<K, V> map = new HashMap<>();
+            this.mapTraversal.forEach((k, v) -> {
+                map.put(k, v.next());
+            });
+            return map;
+        }
+    }
+
+    ///////////
+
     public static final class GroupSideEffectMapReduce<S, K, V> implements MapReduce<K,
Traverser<S>, K, V, Map<K, V>> {
 
         public static final String GROUP_SIDE_EFFECT_STEP_SIDE_EFFECT_KEY = "gremlin.groupSideEffectStep.sideEffectKey";
@@ -217,7 +242,7 @@ public final class GroupSideEffectStep<S, K, V> extends SideEffectStep<S>
implem
 
         @Override
         public void reduce(final K key, final Iterator<Traverser<S>> values,
final ReduceEmitter<K, V> emitter) {
-            final Traversal.Admin<S,V> cloneValueTraversal = this.valueTraversal.clone();
+            final Traversal.Admin<S, V> cloneValueTraversal = this.valueTraversal.clone();
             cloneValueTraversal.addStarts(values);
             emitter.emit(key, cloneValueTraversal.next());
         }
@@ -251,4 +276,5 @@ public final class GroupSideEffectStep<S, K, V> extends SideEffectStep<S>
implem
             return StringFactory.mapReduceString(this, this.getMemoryKey());
         }
     }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/da2477b7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java
index f4ef0a8..e80bae2 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java
@@ -19,11 +19,17 @@
 package org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect;
 
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.SupplyingBarrierStep;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -66,15 +72,18 @@ public final class SideEffectCapStep<S, E> extends SupplyingBarrierStep<S,
E> {
 
     @Override
     protected E supply() {
-        return this.sideEffectKeys.size() == 1 ?
-                this.getTraversal().asAdmin().getSideEffects().<E>get(this.sideEffectKeys.get(0)).get()
:
-                (E) this.getMapOfSideEffects();
+        if (this.sideEffectKeys.size() == 1) {
+            final Object object = this.getTraversal().getSideEffects().<E>get(this.sideEffectKeys.get(0)).get();
+            return (E) (object instanceof ReducingBarrierStep.FinalGet ? ((ReducingBarrierStep.FinalGet)
object).getFinal() : object);
+        } else {
+            return (E) this.getMapOfSideEffects();
+        }
     }
 
     public Map<String, Object> getMapOfSideEffects() {
         final Map<String, Object> sideEffects = new HashMap<>();
         for (final String sideEffectKey : this.sideEffectKeys) {
-            this.getTraversal().asAdmin().getSideEffects().get(sideEffectKey).ifPresent(value
-> sideEffects.put(sideEffectKey, value));
+            this.getTraversal().asAdmin().getSideEffects().get(sideEffectKey).ifPresent(value
-> sideEffects.put(sideEffectKey, value instanceof ReducingBarrierStep.FinalGet ? ((ReducingBarrierStep.FinalGet)
value).getFinal() : value));
         }
         return sideEffects;
     }


Mime
View raw message