tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From florianhockm...@apache.org
Subject [06/45] tinkerpop git commit: TINKERPOP-1996 read()/write() api changes for return type
Date Tue, 31 Jul 2018 20:19:35 GMT
TINKERPOP-1996 read()/write() api changes for return type

No more weird Map status return for read() and write(). Both just work like a terminator and
self iterate to return nothing.


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

Branch: refs/heads/TINKERPOP-1774
Commit: d99909c4e19fcb3ec3b8a8c94eb054a4332ad219
Parents: ff2773a
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Tue Jul 10 14:53:52 2018 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Thu Jul 19 13:39:29 2018 -0400

----------------------------------------------------------------------
 .../traversal/dsl/graph/GraphTraversalSource.java | 18 ++++++++++--------
 .../process/traversal/step/map/ReadStep.java      | 12 ++++--------
 .../process/traversal/step/map/WriteStep.java     | 13 ++++---------
 .../strategy/verification/IoUsageStrategy.java    | 10 ++++++++--
 .../Process/Traversal/GraphTraversalSource.cs     | 12 ++++++------
 .../traversal/strategy/HadoopIoStrategy.java      |  4 ++++
 .../structure/TinkerGraphPlayTest.java            | 10 ++++++++++
 7 files changed, 46 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d99909c4/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
index 9b82108..49e012f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
 import org.apache.tinkerpop.gremlin.process.remote.RemoteConnection;
 import org.apache.tinkerpop.gremlin.process.remote.traversal.strategy.decoration.RemoteStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
@@ -43,6 +44,7 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 
 import java.util.Map;
+import java.util.NoSuchElementException;
 import java.util.Optional;
 import java.util.function.BinaryOperator;
 import java.util.function.Supplier;
@@ -393,18 +395,18 @@ public class GraphTraversalSource implements TraversalSource {
         return traversal.addStep(new GraphStep<>(traversal, Edge.class, true, edgesIds));
     }
 
-    public GraphTraversal<Map<String,Object>, Map<String,Object>> read(final
String localFile) {
+    public <S> GraphTraversal<S, S> read(final String file) {
         final GraphTraversalSource clone = this.clone();
-        clone.bytecode.addStep(GraphTraversal.Symbols.read, localFile);
-        final GraphTraversal.Admin<Map<String,Object>, Map<String,Object>>
traversal = new DefaultGraphTraversal<>(clone);
-        return traversal.addStep(new ReadStep(traversal, localFile));
+        clone.bytecode.addStep(GraphTraversal.Symbols.read, file);
+        final GraphTraversal.Admin<S,S> traversal = new DefaultGraphTraversal<>(clone);
+        return traversal.addStep(new ReadStep<S>(traversal, file)).iterate();
     }
 
-    public GraphTraversal<Map<String,Object>, Map<String,Object>> write(final
String localFile) {
+    public <S> GraphTraversal<S, S> write(final String file) {
         final GraphTraversalSource clone = this.clone();
-        clone.bytecode.addStep(GraphTraversal.Symbols.write, localFile);
-        final GraphTraversal.Admin<Map<String,Object>, Map<String,Object>>
traversal = new DefaultGraphTraversal<>(clone);
-        return traversal.addStep(new WriteStep(traversal, localFile));
+        clone.bytecode.addStep(GraphTraversal.Symbols.write, file);
+        final GraphTraversal.Admin<S,S> traversal = new DefaultGraphTraversal<>(clone);
+        return traversal.addStep(new WriteStep<S>(traversal, file)).iterate();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d99909c4/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ReadStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ReadStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ReadStep.java
index 7c71ab5..99f7e66 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ReadStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ReadStep.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraverserGenerator;
 import org.apache.tinkerpop.gremlin.process.traversal.step.Reading;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.Parameters;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.EmptyTraverser;
 import org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader;
@@ -43,7 +44,7 @@ import java.util.Map;
  *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
-public class ReadStep extends AbstractStep<Map<String,Object>, Map<String,Object>>
implements Reading {
+public class ReadStep<S> extends AbstractStep<S,S> implements Reading {
 
     private Parameters parameters = new Parameters();
     private boolean first = true;
@@ -74,11 +75,10 @@ public class ReadStep extends AbstractStep<Map<String,Object>,
Map<String,Object
     }
 
     @Override
-    protected Traverser.Admin<Map<String,Object>> processNextStart() {
+    protected Traverser.Admin<S> processNextStart() {
         if (!this.first) throw FastNoSuchElementException.instance();
 
         this.first = false;
-        final TraverserGenerator generator = this.getTraversal().getTraverserGenerator();
         final File file = new File(this.file);
         if (!file.exists()) throw new IllegalStateException(this.file + " does not exist");
 
@@ -86,11 +86,7 @@ public class ReadStep extends AbstractStep<Map<String,Object>,
Map<String,Object
             final Graph graph = (Graph) this.traversal.getGraph().get();
             GryoReader.build().create().readGraph(stream, graph);
 
-            final Map<String,Object> stats = new LinkedHashMap<>();
-            stats.put("vertices", IteratorUtils.count(graph.vertices()));
-            stats.put("edges", IteratorUtils.count(graph.edges()));
-
-            return generator.generate(stats, this, 1L);
+            return EmptyTraverser.instance();
         } catch (IOException ioe) {
             throw new IllegalStateException(String.format("Could not read file %s into graph",
this.file), ioe);
         }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d99909c4/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/WriteStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/WriteStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/WriteStep.java
index d27cd24..20ffec9 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/WriteStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/WriteStep.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraverserGenerator;
 import org.apache.tinkerpop.gremlin.process.traversal.step.Writing;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.Parameters;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.EmptyTraverser;
 import org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoWriter;
@@ -43,7 +44,7 @@ import java.util.Map;
  *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
-public class WriteStep extends AbstractStep<Map<String,Object>, Map<String,Object>>
implements Writing {
+public class WriteStep<S> extends AbstractStep<S,S> implements Writing {
 
     private Parameters parameters = new Parameters();
     private boolean first = true;
@@ -74,22 +75,16 @@ public class WriteStep extends AbstractStep<Map<String,Object>,
Map<String,Objec
     }
 
     @Override
-    protected Traverser.Admin<Map<String,Object>> processNextStart() {
+    protected Traverser.Admin<S> processNextStart() {
         if (!this.first) throw FastNoSuchElementException.instance();
 
         this.first = false;
-        final TraverserGenerator generator = this.getTraversal().getTraverserGenerator();
-
         final File file = new File(this.file);
         try (final OutputStream stream = new FileOutputStream(file)) {
             final Graph graph = (Graph) this.traversal.getGraph().get();
             GryoWriter.build().create().writeGraph(stream, graph);
 
-            final Map<String, Object> stats = new LinkedHashMap<>();
-            stats.put("vertices", IteratorUtils.count(graph.vertices()));
-            stats.put("edges", IteratorUtils.count(graph.edges()));
-
-            return generator.generate(stats, this, 1L);
+            return EmptyTraverser.instance();
         } catch (IOException ioe) {
             throw new IllegalStateException(String.format("Could not write file %s from graph",
this.file), ioe);
         }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d99909c4/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/IoUsageStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/IoUsageStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/IoUsageStrategy.java
index e9c7ec8..b4a0669 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/IoUsageStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/IoUsageStrategy.java
@@ -18,10 +18,12 @@
  */
 package org.apache.tinkerpop.gremlin.process.traversal.strategy.verification;
 
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.step.filter.NoneStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.ReadStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.WriteStep;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
@@ -52,8 +54,12 @@ public final class IoUsageStrategy extends AbstractTraversalStrategy<TraversalSt
 
     @Override
     public void apply(final Traversal.Admin<?, ?> traversal) {
-        if ((traversal.getStartStep() instanceof ReadStep || traversal.getStartStep() instanceof
WriteStep) && traversal.getSteps().size() > 1) {
-            throw new VerificationException("The read() or write() steps must be the first
and only step in the traversal - they cannot be used with other steps", traversal);
+        final Step start = traversal.getStartStep();
+        final Step end = traversal.getEndStep();
+        if ((start instanceof ReadStep || start instanceof WriteStep) && end != start)
{
+            if ((end instanceof NoneStep && traversal.getSteps().size() > 2))
{
+                throw new VerificationException("The read() or write() steps must be the
first and only step in the traversal - they cannot be used with other steps", traversal);
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d99909c4/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs
index 630ac28..4292850 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs
@@ -337,10 +337,10 @@ namespace Gremlin.Net.Process.Traversal
         ///     Spawns a <see cref="GraphTraversal{SType, EType}" /> off this graph
traversal source and adds the read step to that
         ///     traversal.
         /// </summary>
-        public GraphTraversal<IDictionary<string, object>, IDictionary<string,
object>> Read(string localFile)
+        public GraphTraversal<S, S> Read<S>(string file)
         {
-            var traversal = new GraphTraversal<IDictionary<string, object>, IDictionary<string,
object>>(TraversalStrategies, new Bytecode(Bytecode));
-                traversal.Bytecode.AddStep("read", localFile);
+            var traversal = new GraphTraversal<S, S>(TraversalStrategies, new Bytecode(Bytecode));
+                traversal.Bytecode.AddStep("read", file);
             return traversal;
         }
 
@@ -348,10 +348,10 @@ namespace Gremlin.Net.Process.Traversal
         ///     Spawns a <see cref="GraphTraversal{SType, EType}" /> off this graph
traversal source and adds the write step to that
         ///     traversal.
         /// </summary>
-        public GraphTraversal<IDictionary<string, object>, IDictionary<string,
object>> Write(string localFile)
+        public GraphTraversal<S, S> Write<S>(string file)
         {
-            var traversal = new GraphTraversal<IDictionary<string, object>, IDictionary<string,
object>>(TraversalStrategies, new Bytecode(Bytecode));
-                traversal.Bytecode.AddStep("write", localFile);
+            var traversal = new GraphTraversal<S, S>(TraversalStrategies, new Bytecode(Bytecode));
+                traversal.Bytecode.AddStep("write", file);
             return traversal;
         }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d99909c4/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/traversal/strategy/HadoopIoStrategy.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/traversal/strategy/HadoopIoStrategy.java
b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/traversal/strategy/HadoopIoStrategy.java
index d8d8bab..7e0e23c 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/traversal/strategy/HadoopIoStrategy.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/process/computer/traversal/strategy/HadoopIoStrategy.java
@@ -26,6 +26,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.step.Reading;
 import org.apache.tinkerpop.gremlin.process.traversal.step.Writing;
+import org.apache.tinkerpop.gremlin.process.traversal.step.filter.NoneStep;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
 
@@ -60,6 +61,9 @@ public final class HadoopIoStrategy extends AbstractTraversalStrategy<TraversalS
 
             TraversalHelper.replaceStep((Step) writing, hadoopWriteStep, traversal);
         }
+
+        if (traversal.getEndStep() instanceof NoneStep)
+            traversal.removeStep(1);
     }
 
     public static HadoopIoStrategy instance() {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d99909c4/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index e0018fc..82bf2d7 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -28,6 +28,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSo
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.PathRetractionStrategy;
 import org.apache.tinkerpop.gremlin.structure.*;
+import org.apache.tinkerpop.gremlin.structure.io.IoTest;
 import org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLIo;
 import org.apache.tinkerpop.gremlin.util.TimeUtil;
 import org.junit.Ignore;
@@ -334,4 +335,13 @@ public class TinkerGraphPlayTest {
         System.out.println(g.V().as("a").both().as("b").dedup("a", "b").by(T.label).select("a",
"b").toList());
 
     }
+
+    @Test
+    public void testBlah() {
+        TinkerGraph graph = TinkerGraph.open();
+        GraphTraversalSource g = graph.traversal();
+        g.read("../data/tinkerpop-modern.kryo");
+
+        IoTest.assertModernGraph(graph, true, false);
+    }
 }


Mime
View raw message