You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/06/21 22:46:02 UTC
[1/6] tinkerpop git commit: TraversalExplanation now supports word
wrapping and VertexProgamStep.toStrings() have GraphFilter information
attached.
Repository: tinkerpop
Updated Branches:
refs/heads/master 408755de3 -> 82afed3a4
TraversalExplanation now supports word wrapping and VertexProgamStep.toStrings() have GraphFilter information attached.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/fc62efec
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/fc62efec
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/fc62efec
Branch: refs/heads/master
Commit: fc62efec4d578b5e767676b04789cf35535f53f0
Parents: 1a526eb
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Jun 15 07:00:44 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Jun 15 07:00:44 2016 -0600
----------------------------------------------------------------------
.../gremlin/process/computer/GraphFilter.java | 11 ++++
.../step/map/PageRankVertexProgramStep.java | 3 +-
.../step/map/PeerPressureVertexProgramStep.java | 3 +-
.../step/map/ProgramVertexProgramStep.java | 3 +-
.../step/map/TraversalVertexProgramStep.java | 3 +-
.../traversal/util/TraversalExplanation.java | 56 ++++++++++++++++++--
.../util/TraversalExplanationTest.java | 42 ++++++++++++++-
7 files changed, 111 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc62efec/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
index 59c654d..3718d16 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
@@ -83,6 +83,17 @@ public final class GraphFilter implements Cloneable, Serializable {
private Map<Direction, Map<String, Legal>> edgeLegality = new HashMap<>();
private boolean allowNoEdges = false;
+ public GraphFilter() {
+ // no args constructor
+ }
+
+ public GraphFilter(final Computer computer) {
+ if (null != computer.getVertices())
+ this.setVertexFilter(computer.getVertices());
+ if (null != computer.getEdges())
+ this.setEdgeFilter(computer.getEdges());
+ }
+
/**
* Set the filter for selecting vertices from the source graph.
* The vertex filter can only access the vertex, its properties, and its properties properties.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc62efec/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
index fcb2eec..364d092 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
@@ -19,6 +19,7 @@
package org.apache.tinkerpop.gremlin.process.computer.traversal.step.map;
+import org.apache.tinkerpop.gremlin.process.computer.GraphFilter;
import org.apache.tinkerpop.gremlin.process.computer.Memory;
import org.apache.tinkerpop.gremlin.process.computer.ranking.pagerank.PageRankVertexProgram;
import org.apache.tinkerpop.gremlin.process.computer.traversal.lambda.HaltedTraversersCountTraversal;
@@ -78,7 +79,7 @@ public final class PageRankVertexProgramStep extends VertexProgramStep implement
@Override
public String toString() {
- return StringFactory.stepString(this, this.edgeTraversal.get(), this.pageRankProperty, this.times);
+ return StringFactory.stepString(this, this.edgeTraversal.get(), this.pageRankProperty, this.times, new GraphFilter(this.computer));
}
@Override
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc62efec/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PeerPressureVertexProgramStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PeerPressureVertexProgramStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PeerPressureVertexProgramStep.java
index 0ea5112..47d4160 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PeerPressureVertexProgramStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PeerPressureVertexProgramStep.java
@@ -19,6 +19,7 @@
package org.apache.tinkerpop.gremlin.process.computer.traversal.step.map;
+import org.apache.tinkerpop.gremlin.process.computer.GraphFilter;
import org.apache.tinkerpop.gremlin.process.computer.Memory;
import org.apache.tinkerpop.gremlin.process.computer.clustering.peerpressure.PeerPressureVertexProgram;
import org.apache.tinkerpop.gremlin.process.computer.traversal.lambda.HaltedTraversersCountTraversal;
@@ -81,7 +82,7 @@ public final class PeerPressureVertexProgramStep extends VertexProgramStep imple
@Override
public String toString() {
- return StringFactory.stepString(this, this.edgeTraversal.get(), this.clusterProperty, this.times);
+ return StringFactory.stepString(this, this.edgeTraversal.get(), this.clusterProperty, this.times, new GraphFilter(this.computer));
}
@Override
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc62efec/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ProgramVertexProgramStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ProgramVertexProgramStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ProgramVertexProgramStep.java
index 82e70dd..31eb04b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ProgramVertexProgramStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ProgramVertexProgramStep.java
@@ -20,6 +20,7 @@
package org.apache.tinkerpop.gremlin.process.computer.traversal.step.map;
import org.apache.commons.configuration.MapConfiguration;
+import org.apache.tinkerpop.gremlin.process.computer.GraphFilter;
import org.apache.tinkerpop.gremlin.process.computer.Memory;
import org.apache.tinkerpop.gremlin.process.computer.VertexProgram;
import org.apache.tinkerpop.gremlin.process.computer.traversal.TraversalVertexProgram;
@@ -67,6 +68,6 @@ public final class ProgramVertexProgramStep extends VertexProgramStep {
@Override
public String toString() {
- return StringFactory.stepString(this, this.toStringOfVertexProgram);
+ return StringFactory.stepString(this, this.toStringOfVertexProgram, new GraphFilter(this.computer));
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc62efec/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/TraversalVertexProgramStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/TraversalVertexProgramStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/TraversalVertexProgramStep.java
index 58e44a2..0eee43a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/TraversalVertexProgramStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/TraversalVertexProgramStep.java
@@ -20,6 +20,7 @@
package org.apache.tinkerpop.gremlin.process.computer.traversal.step.map;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.computer.GraphFilter;
import org.apache.tinkerpop.gremlin.process.computer.Memory;
import org.apache.tinkerpop.gremlin.process.computer.traversal.MemoryTraversalSideEffects;
import org.apache.tinkerpop.gremlin.process.computer.traversal.TraversalVertexProgram;
@@ -54,7 +55,7 @@ public final class TraversalVertexProgramStep extends VertexProgramStep implemen
@Override
public String toString() {
- return StringFactory.stepString(this, this.computerTraversal.get());
+ return StringFactory.stepString(this, this.computerTraversal.get(), new GraphFilter(this.computer));
}
@Override
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc62efec/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java
index 98cef69..675291d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java
@@ -85,10 +85,26 @@ public class TraversalExplanation implements Serializable {
*/
@Override
public String toString() {
+ final int maxLineLength = 75;
final String originalTraversal = "Original Traversal";
final String finalTraversal = "Final Traversal";
- final int maxStrategyColumnLength = this.strategyTraversals.stream().map(Pair::getValue0).map(Object::toString).map(String::length).max(Comparator.<Integer>naturalOrder()).orElse(15);
- final int maxTraversalColumnLength = Stream.concat(Stream.of(Pair.with(null, this.traversal)), this.strategyTraversals.stream()).map(Pair::getValue1).map(Object::toString).map(String::length).max(Comparator.<Integer>naturalOrder()).get();
+ final int maxStrategyColumnLength = this.strategyTraversals.stream()
+ .map(Pair::getValue0)
+ .map(Object::toString)
+ .map(String::length)
+ .max(Comparator.naturalOrder())
+ .orElse(15);
+ final int newLineIndent = maxStrategyColumnLength + 10;
+ int maxTraversalColumnLength = Stream.concat(Stream.of(Pair.with(null, this.traversal)), this.strategyTraversals.stream())
+ .map(Pair::getValue1)
+ .map(Object::toString)
+ .map(s -> wordWrap(s, maxLineLength, newLineIndent))
+ .flatMap(s -> Stream.of(s.split("\n")))
+ .map(String::trim)
+ .map(s -> s.trim().startsWith("[") ? s : " " + s) // 3 indent on new lines
+ .map(String::length)
+ .max(Comparator.naturalOrder())
+ .get();
final StringBuilder builder = new StringBuilder("Traversal Explanation\n");
for (int i = 0; i < (maxStrategyColumnLength + 7 + maxTraversalColumnLength); i++) {
@@ -99,7 +115,7 @@ public class TraversalExplanation implements Serializable {
for (int i = 0; i < maxStrategyColumnLength - originalTraversal.length() + 7; i++) {
builder.append(" ");
}
- builder.append(this.traversal.toString());
+ builder.append(wordWrap(this.traversal.toString(), maxLineLength, newLineIndent));
builder.append("\n\n");
for (final Pair<TraversalStrategy, Traversal.Admin<?, ?>> pairs : this.strategyTraversals) {
builder.append(pairs.getValue0());
@@ -111,15 +127,45 @@ public class TraversalExplanation implements Serializable {
for (int i = 0; i < 3; i++) {
builder.append(" ");
}
- builder.append(pairs.getValue1().toString()).append("\n");
+ builder.append(wordWrap(pairs.getValue1().toString(), maxLineLength, newLineIndent)).append("\n");
}
builder.append("\n");
builder.append(finalTraversal);
for (int i = 0; i < maxStrategyColumnLength - finalTraversal.length() + 7; i++) {
builder.append(" ");
}
- builder.append(this.strategyTraversals.size() > 0 ? this.strategyTraversals.get(this.strategyTraversals.size() - 1).getValue1() : this.traversal);
+ builder.append(wordWrap((this.strategyTraversals.size() > 0 ?
+ this.strategyTraversals.get(this.strategyTraversals.size() - 1).getValue1().toString() :
+ this.traversal.toString()), maxLineLength, newLineIndent));
return builder.toString();
}
+ private String wordWrap(final String longString, final int maxLengthPerLine, final int newLineIndent) {
+ if (longString.length() <= maxLengthPerLine)
+ return longString;
+
+ StringBuilder builder = new StringBuilder();
+ int counter = 0;
+ for (final String shortString : longString.split(", ")) {
+ if (0 == counter)
+ builder.append(shortString).append(", ");
+ else if (counter < maxLengthPerLine)
+ builder.append(shortString).append(", ");
+ else {
+ builder.deleteCharAt(builder.length() - 1); // remove the " "
+ builder.append("\n");
+ for (int i = 0; i < newLineIndent; i++) {
+ builder.append(" ");
+ }
+ builder.append(shortString).append(", ");
+ counter = 0;
+ }
+ counter = counter + shortString.length();
+ }
+
+ return builder
+ .delete(builder.length() - 2, builder.length()) // remove the final ", "
+ .toString();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc62efec/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java
index 3059879..57841e4 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java
@@ -22,11 +22,15 @@ package org.apache.tinkerpop.gremlin.process.traversal.util;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.junit.Test;
+import java.util.stream.Stream;
+
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
@@ -43,6 +47,40 @@ public class TraversalExplanationTest {
}
@Test
+ public void shouldWordWrapCorrectly() {
+ GraphTraversal<?, ?> traversal = __.V().out().out();
+ String toString = traversal.explain().toString();
+ assertFalse(toString.contains("VertexStep(OUT,vertex),\n"));
+ //System.out.println(toString);
+ ///
+ traversal = __.V().out().out().out().out();
+ toString = traversal.explain().toString();
+ assertTrue(toString.contains("VertexStep(OUT,vertex),\n"));
+ //System.out.println(toString);
+ ///
+ for (int i = 0; i < 30; i++) {
+ traversal = __.V();
+ for (int j = 0; j < i; j++) {
+ traversal.out();
+ }
+ traversal.asAdmin().setStrategies(TraversalStrategies.GlobalCache.getStrategies(Graph.class));
+ toString = traversal.explain().toString();
+ if (i < 4)
+ assertFalse(toString.contains("VertexStep(OUT,vertex),\n"));
+ else {
+ assertFalse(Stream.of(toString.split("\n"))
+ .filter(s -> s.startsWith(" "))
+ .map(String::trim)
+ .filter(s -> Character.isLowerCase(s.charAt(0)))
+ .findAny()
+ .isPresent()); // all indented word wraps should start with steps
+ assertTrue(toString.contains("VertexStep(OUT,vertex),\n"));
+ }
+ //System.out.println(toString);
+ }
+ }
+
+ @Test
public void shouldApplyStrategiesCorrectly() {
Traversal.Admin<?, ?> traversal = __.out().count().asAdmin();
traversal.setStrategies(TraversalStrategies.GlobalCache.getStrategies(Graph.class));
@@ -64,8 +102,10 @@ public class TraversalExplanationTest {
///
traversal = __.outE().inV().group().by(__.inE().outV().groupCount().by(__.both().count().is(P.gt(2)))).asAdmin();
traversal.setStrategies(TraversalStrategies.GlobalCache.getStrategies(Graph.class).clone());
+ // System.out.println(traversal.explain());
found = 0;
- for (final String line : traversal.explain().toString().split("\n")) {
+ for (final String line : traversal.explain().toString().split("]\n")) { // need to split cause of word wrap
+ //System.out.println(line + "\n\n");
if (line.contains("IncidentToAdjacentStrategy") && line.contains("[VertexStep(IN,vertex)"))
found++;
if (line.contains("IncidentToAdjacentStrategy") && line.contains("[VertexStep(OUT,vertex)"))
[3/6] tinkerpop git commit: TraversalExplanation now how
prettyPrint(), prettyPrint(int maxLineLength),
and toString(). Console will detect a TraversalExplaination and use
prettyPrint(TerminalFactory.get().getWidth()). If the TerminalFactory is
'bad' the
Posted by ok...@apache.org.
TraversalExplanation now how prettyPrint(), prettyPrint(int maxLineLength), and toString(). Console will detect a TraversalExplaination and use prettyPrint(TerminalFactory.get().getWidth()). If the TerminalFactory is 'bad' then a default reasonable value is use -- people say some Java versions give -1 for getWidth().
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/21a533d4
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/21a533d4
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/21a533d4
Branch: refs/heads/master
Commit: 21a533d4f11e1d8b614230b1073ed0e0603ccaa3
Parents: a4771b6
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Jun 16 12:49:33 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Jun 16 12:49:33 2016 -0600
----------------------------------------------------------------------
.../tinkerpop/gremlin/console/Console.groovy | 12 ++++++---
.../traversal/util/TraversalExplanation.java | 28 +++++++++++++-------
.../util/TraversalExplanationTest.java | 23 ++++++++++++----
3 files changed, 46 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21a533d4/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index 5108948..3d748eb 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -18,6 +18,7 @@
*/
package org.apache.tinkerpop.gremlin.console
+import jline.TerminalFactory
import org.apache.commons.cli.Option
import org.apache.tinkerpop.gremlin.console.commands.GremlinSetCommand
import org.apache.tinkerpop.gremlin.console.commands.InstallCommand
@@ -29,6 +30,7 @@ import org.apache.tinkerpop.gremlin.console.plugin.PluggedIn
import org.apache.tinkerpop.gremlin.groovy.loaders.GremlinLoader
import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin
import jline.console.history.FileHistory
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalExplanation
import org.apache.tinkerpop.gremlin.util.Gremlin
import org.apache.tinkerpop.gremlin.util.iterator.ArrayIterator
import org.codehaus.groovy.tools.shell.AnsiDetector
@@ -113,8 +115,8 @@ class Console {
groovy = new GremlinGroovysh(mediator)
- def commandsToRemove = groovy.getRegistry().commands().findAll{it instanceof SetCommand}
- commandsToRemove.each {groovy.getRegistry().remove(it)}
+ def commandsToRemove = groovy.getRegistry().commands().findAll { it instanceof SetCommand }
+ commandsToRemove.each { groovy.getRegistry().remove(it) }
groovy.register(new GremlinSetCommand(groovy))
groovy.register(new UninstallCommand(groovy, mediator))
groovy.register(new InstallCommand(groovy, mediator))
@@ -209,7 +211,7 @@ class Console {
io.out.println(buildResultPrompt() + ((null == object) ? NULL : object.toString()))
counter++;
}
- if(this.tempIterator.hasNext())
+ if (this.tempIterator.hasNext())
io.out.println(ELLIPSIS);
this.tempIterator = Collections.emptyIterator();
return null
@@ -249,6 +251,10 @@ class Console {
this.tempIterator = Collections.emptyIterator();
return null
}
+ } else if (result instanceof TraversalExplanation) {
+ final int width = TerminalFactory.get().getWidth() - 25
+ io.out.println(buildResultPrompt() + result.prettyPrint(width < 10 ? 100 : width))
+ return null
} else {
io.out.println(buildResultPrompt() + ((null == result) ? NULL : result.toString()))
return null
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21a533d4/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java
index 675291d..2baccdb 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java
@@ -78,14 +78,21 @@ public class TraversalExplanation implements Serializable {
return this.traversal;
}
+ @Override
+ public String toString() {
+ return this.prettyPrint(Integer.MAX_VALUE);
+ }
+
+ public String prettyPrint() {
+ return this.prettyPrint(100);
+ }
+
/**
* A pretty-print representation of the traversal explanation.
*
* @return a {@link String} representation of the traversal explanation
*/
- @Override
- public String toString() {
- final int maxLineLength = 75;
+ public String prettyPrint(final int maxLineLength) {
final String originalTraversal = "Original Traversal";
final String finalTraversal = "Final Traversal";
final int maxStrategyColumnLength = this.strategyTraversals.stream()
@@ -95,10 +102,13 @@ public class TraversalExplanation implements Serializable {
.max(Comparator.naturalOrder())
.orElse(15);
final int newLineIndent = maxStrategyColumnLength + 10;
- int maxTraversalColumnLength = Stream.concat(Stream.of(Pair.with(null, this.traversal)), this.strategyTraversals.stream())
+ final int maxTraversalColumn = maxLineLength - newLineIndent;
+ if (maxTraversalColumn < 1)
+ throw new IllegalArgumentException("The maximum line length is too small to present the " + TraversalExplanation.class.getSimpleName() + ": " + maxLineLength);
+ int largestTraversalColumn = Stream.concat(Stream.of(Pair.with(null, this.traversal)), this.strategyTraversals.stream())
.map(Pair::getValue1)
.map(Object::toString)
- .map(s -> wordWrap(s, maxLineLength, newLineIndent))
+ .map(s -> wordWrap(s, maxTraversalColumn, newLineIndent))
.flatMap(s -> Stream.of(s.split("\n")))
.map(String::trim)
.map(s -> s.trim().startsWith("[") ? s : " " + s) // 3 indent on new lines
@@ -107,7 +117,7 @@ public class TraversalExplanation implements Serializable {
.get();
final StringBuilder builder = new StringBuilder("Traversal Explanation\n");
- for (int i = 0; i < (maxStrategyColumnLength + 7 + maxTraversalColumnLength); i++) {
+ for (int i = 0; i < (maxStrategyColumnLength + 7 + largestTraversalColumn); i++) {
builder.append("=");
}
builder.append("\n");
@@ -115,7 +125,7 @@ public class TraversalExplanation implements Serializable {
for (int i = 0; i < maxStrategyColumnLength - originalTraversal.length() + 7; i++) {
builder.append(" ");
}
- builder.append(wordWrap(this.traversal.toString(), maxLineLength, newLineIndent));
+ builder.append(wordWrap(this.traversal.toString(), maxTraversalColumn, newLineIndent));
builder.append("\n\n");
for (final Pair<TraversalStrategy, Traversal.Admin<?, ?>> pairs : this.strategyTraversals) {
builder.append(pairs.getValue0());
@@ -127,7 +137,7 @@ public class TraversalExplanation implements Serializable {
for (int i = 0; i < 3; i++) {
builder.append(" ");
}
- builder.append(wordWrap(pairs.getValue1().toString(), maxLineLength, newLineIndent)).append("\n");
+ builder.append(wordWrap(pairs.getValue1().toString(), maxTraversalColumn, newLineIndent)).append("\n");
}
builder.append("\n");
builder.append(finalTraversal);
@@ -136,7 +146,7 @@ public class TraversalExplanation implements Serializable {
}
builder.append(wordWrap((this.strategyTraversals.size() > 0 ?
this.strategyTraversals.get(this.strategyTraversals.size() - 1).getValue1().toString() :
- this.traversal.toString()), maxLineLength, newLineIndent));
+ this.traversal.toString()), maxTraversalColumn, newLineIndent));
return builder.toString();
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/21a533d4/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java
index 57841e4..3350a87 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java
@@ -49,12 +49,12 @@ public class TraversalExplanationTest {
@Test
public void shouldWordWrapCorrectly() {
GraphTraversal<?, ?> traversal = __.V().out().out();
- String toString = traversal.explain().toString();
+ String toString = traversal.explain().prettyPrint();
assertFalse(toString.contains("VertexStep(OUT,vertex),\n"));
//System.out.println(toString);
///
traversal = __.V().out().out().out().out();
- toString = traversal.explain().toString();
+ toString = traversal.explain().prettyPrint();
assertTrue(toString.contains("VertexStep(OUT,vertex),\n"));
//System.out.println(toString);
///
@@ -64,8 +64,8 @@ public class TraversalExplanationTest {
traversal.out();
}
traversal.asAdmin().setStrategies(TraversalStrategies.GlobalCache.getStrategies(Graph.class));
- toString = traversal.explain().toString();
- if (i < 4)
+ toString = traversal.explain().prettyPrint();
+ if (i < 3)
assertFalse(toString.contains("VertexStep(OUT,vertex),\n"));
else {
assertFalse(Stream.of(toString.split("\n"))
@@ -116,6 +116,19 @@ public class TraversalExplanationTest {
found++;
}
assertEquals(4, found);
- // System.out.println(traversal.explain());
+ //
+ found = 0;
+ for (final String line : traversal.explain().prettyPrint().split("]\n")) { // need to split cause of word wrap
+ //System.out.println(line + "\n\n");
+ if (line.contains("IncidentToAdjacentStrategy") && line.contains("[VertexStep(IN,vertex)"))
+ found++;
+ if (line.contains("IncidentToAdjacentStrategy") && line.contains("[VertexStep(OUT,vertex)"))
+ found++;
+ if (line.contains("AdjacentToIncidentStrategy") && line.contains("[VertexStep(BOTH,edge)"))
+ found++;
+ if (line.contains("RangeByIsCountStrategy") && line.contains("RangeGlobalStep(0,3)"))
+ found++;
+ }
+ assertEquals(4, found);
}
}
[4/6] tinkerpop git commit: made things safer -- not longer wraps by
step name, but by character. much cleaner.
Posted by ok...@apache.org.
made things safer -- not longer wraps by step name, but by character. much cleaner.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/090efe3b
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/090efe3b
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/090efe3b
Branch: refs/heads/master
Commit: 090efe3be4b40e90dba4731d8233b5dd62c08204
Parents: 21a533d
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Jun 21 16:44:19 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Jun 21 16:44:19 2016 -0600
----------------------------------------------------------------------
.../tinkerpop/gremlin/console/Console.groovy | 6 ++---
.../traversal/util/TraversalExplanation.java | 23 +++++++++-----------
.../util/TraversalExplanationTest.java | 16 +++++++++-----
3 files changed, 23 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/090efe3b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index 3d748eb..8dcb272 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -19,6 +19,7 @@
package org.apache.tinkerpop.gremlin.console
import jline.TerminalFactory
+import jline.console.history.FileHistory
import org.apache.commons.cli.Option
import org.apache.tinkerpop.gremlin.console.commands.GremlinSetCommand
import org.apache.tinkerpop.gremlin.console.commands.InstallCommand
@@ -29,7 +30,6 @@ import org.apache.tinkerpop.gremlin.console.commands.UninstallCommand
import org.apache.tinkerpop.gremlin.console.plugin.PluggedIn
import org.apache.tinkerpop.gremlin.groovy.loaders.GremlinLoader
import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin
-import jline.console.history.FileHistory
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalExplanation
import org.apache.tinkerpop.gremlin.util.Gremlin
import org.apache.tinkerpop.gremlin.util.iterator.ArrayIterator
@@ -252,8 +252,8 @@ class Console {
return null
}
} else if (result instanceof TraversalExplanation) {
- final int width = TerminalFactory.get().getWidth() - 25
- io.out.println(buildResultPrompt() + result.prettyPrint(width < 10 ? 100 : width))
+ final int width = TerminalFactory.get().getWidth();
+ io.out.println(buildResultPrompt() + result.prettyPrint(width < 20 ? 80 : width))
return null
} else {
io.out.println(buildResultPrompt() + ((null == result) ? NULL : result.toString()))
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/090efe3b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java
index 2baccdb..6e3692a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanation.java
@@ -156,26 +156,23 @@ public class TraversalExplanation implements Serializable {
StringBuilder builder = new StringBuilder();
int counter = 0;
- for (final String shortString : longString.split(", ")) {
- if (0 == counter)
- builder.append(shortString).append(", ");
- else if (counter < maxLengthPerLine)
- builder.append(shortString).append(", ");
- else {
- builder.deleteCharAt(builder.length() - 1); // remove the " "
+ for (int i = 0; i < longString.length(); i++) {
+ if (0 == counter) {
+ builder.append(longString.charAt(i));
+ } else if (counter < maxLengthPerLine) {
+ builder.append(longString.charAt(i));
+ } else {
builder.append("\n");
- for (int i = 0; i < newLineIndent; i++) {
+ for (int j = 0; j < newLineIndent; j++) {
builder.append(" ");
}
- builder.append(shortString).append(", ");
+ builder.append(longString.charAt(i));
counter = 0;
}
- counter = counter + shortString.length();
+ counter++;
}
- return builder
- .delete(builder.length() - 2, builder.length()) // remove the final ", "
- .toString();
+ return builder.toString();
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/090efe3b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java
index 3350a87..3040fe8 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalExplanationTest.java
@@ -55,7 +55,7 @@ public class TraversalExplanationTest {
///
traversal = __.V().out().out().out().out();
toString = traversal.explain().prettyPrint();
- assertTrue(toString.contains("VertexStep(OUT,vertex),\n"));
+ assertTrue(toString.contains("VertexStep(OUT,vertex),"));
//System.out.println(toString);
///
for (int i = 0; i < 30; i++) {
@@ -68,15 +68,20 @@ public class TraversalExplanationTest {
if (i < 3)
assertFalse(toString.contains("VertexStep(OUT,vertex),\n"));
else {
- assertFalse(Stream.of(toString.split("\n"))
+ assertTrue(Stream.of(toString.split("\n"))
.filter(s -> s.startsWith(" "))
.map(String::trim)
.filter(s -> Character.isLowerCase(s.charAt(0)))
.findAny()
.isPresent()); // all indented word wraps should start with steps
- assertTrue(toString.contains("VertexStep(OUT,vertex),\n"));
+ assertTrue(toString.contains("vertex"));
}
- //System.out.println(toString);
+ for (int j = 80; j < 200; j++) {
+ for (final String line : traversal.explain().prettyPrint(j).split("\n")) {
+ assertTrue(line.length() <= j);
+ }
+ }
+ // System.out.println(toString);
}
}
@@ -118,8 +123,7 @@ public class TraversalExplanationTest {
assertEquals(4, found);
//
found = 0;
- for (final String line : traversal.explain().prettyPrint().split("]\n")) { // need to split cause of word wrap
- //System.out.println(line + "\n\n");
+ for (final String line : traversal.explain().prettyPrint(158).split("]\n")) { // need to split cause of word wrap
if (line.contains("IncidentToAdjacentStrategy") && line.contains("[VertexStep(IN,vertex)"))
found++;
if (line.contains("IncidentToAdjacentStrategy") && line.contains("[VertexStep(OUT,vertex)"))
[5/6] tinkerpop git commit: Merge branch 'master' into TINKERPOP-1332
Posted by ok...@apache.org.
Merge branch 'master' into TINKERPOP-1332
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/7dfd0ddc
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/7dfd0ddc
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/7dfd0ddc
Branch: refs/heads/master
Commit: 7dfd0ddcd836aba34d2eec83bc2844cbc1d03c67
Parents: 090efe3 408755d
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Jun 21 16:44:29 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Jun 21 16:44:29 2016 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 2 +
bin/validate-distribution.sh | 9 +-
docs/src/dev/developer/administration.asciidoc | 5 +-
.../developer/development-environment.asciidoc | 4 +-
docs/src/dev/provider/index.asciidoc | 67 +
docs/src/recipes/centrality.asciidoc | 6 +
.../reference/implementations-hadoop.asciidoc | 70 +-
.../reference/implementations-neo4j.asciidoc | 77 +-
docs/src/reference/the-traversal.asciidoc | 3 +-
docs/static/images/neo4j-ha.png | Bin 0 -> 108249 bytes
docs/static/images/tinkerpop3.graffle | 23433 ++++++++---------
.../gremlin/process/remote/RemoteGraph.java | 20 +-
.../decoration/HaltedTraverserStrategy.java | 8 +-
.../strategy/decoration/SubgraphStrategy.java | 40 +-
.../driver/remote/DriverRemoteConnection.java | 3 +-
.../op/traversal/TraversalOpProcessor.java | 21 +-
.../process/traversal/step/map/OrderTest.java | 1 +
.../decoration/SubgraphStrategyProcessTest.java | 22 +
18 files changed, 11866 insertions(+), 11925 deletions(-)
----------------------------------------------------------------------
[6/6] tinkerpop git commit: updated CHANGELOG.
Posted by ok...@apache.org.
updated CHANGELOG.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/82afed3a
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/82afed3a
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/82afed3a
Branch: refs/heads/master
Commit: 82afed3a482a287241ae5a016bc2e14f01785b21
Parents: 7dfd0dd
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Jun 21 16:45:57 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Jun 21 16:45:57 2016 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/82afed3a/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 1ba08d4..94bb67e 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/incubator-tinkerpop/master/docs/
TinkerPop 3.2.1 (NOT OFFICIALLY RELEASED YET)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+* `TraversalExplanation.prettyPrint()` exists which provides word wrapping and GremlinConsole is smart to use console width to control `toString()`.
* `TraversalOpProcessor` (`RemoteConnection`) uses `HaltedTraverserStrategy` metadata to determine detachment procedure prior to returning results.
* Allow DFS paths in `HADOOP_GREMLIN_LIBS`.
* Added a safer serializer infrastructure for use with `SparkGraphComputer` that uses `KryoSerializer` and the new `GryoRegistrator`.
[2/6] tinkerpop git commit: Merge branch 'master' into TINKERPOP-1332
Posted by ok...@apache.org.
Merge branch 'master' into TINKERPOP-1332
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/a4771b6c
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/a4771b6c
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/a4771b6c
Branch: refs/heads/master
Commit: a4771b6c9f8c02a94f4735fea20b82d0ab1e1671
Parents: fc62efe c1b4dae
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Jun 15 07:07:52 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Jun 15 07:07:52 2016 -0600
----------------------------------------------------------------------
.../main/java/org/apache/tinkerpop/gremlin/driver/ResultQueue.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------