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 2015/06/30 18:31:21 UTC
[1/2] incubator-tinkerpop git commit: added MapKeysStep and
MapValuesStep to split apart the keys or values of a Map respectively.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master 0a1861dec -> b5186e28a
added MapKeysStep and MapValuesStep to split apart the keys or values of a Map respectively.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/b5186e28
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/b5186e28
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/b5186e28
Branch: refs/heads/master
Commit: b5186e28ad9349cb6da3f61fc230a6b001e1a466
Parents: 2452a8c
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Jun 30 10:30:55 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Jun 30 10:31:02 2015 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../traversal/dsl/graph/GraphTraversal.java | 10 +++++
.../gremlin/process/traversal/dsl/graph/__.java | 14 +++++++
.../process/traversal/step/map/MapKeysStep.java | 43 ++++++++++++++++++++
.../traversal/step/map/MapValuesStep.java | 43 ++++++++++++++++++++
5 files changed, 111 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b5186e28/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index cdd52b2..1c10d9e 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,7 @@ image::http://www.tinkerpop.com/docs/current/images/gremlin-hindu.png[width=225]
TinkerPop 3.0.0.GA (NOT OFFICIALLY RELEASED YET)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+* Added `mapKeys()` (`MapKeyStep`) and `mapValues()` (`MapValueStep`) to get the keys and values of a map, respectively.
* `select()` no longer supports empty arguments. The user must specify the keys they are selecting.
* `MatchStep` and `match()` no longer have a "start label" parameter -- it is computed if the incoming traverser does not have requisite labels.
* Turned transactional testing back on in Gremlin Server using Neo4j.
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b5186e28/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
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 80788bc..f8aa98f 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
@@ -76,6 +76,8 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.IdStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.LabelStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.LambdaFlatMapStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.LambdaMapStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.MapKeysStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.MapValuesStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MaxGlobalStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MaxLocalStep;
@@ -459,6 +461,14 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
return this.asAdmin().addStep(new PropertyMapStep<>(this.asAdmin(), includeTokens, PropertyType.VALUE, propertyKeys));
}
+ public default <E2> GraphTraversal<S, E2> mapValues() {
+ return this.asAdmin().addStep(new MapValuesStep<>(this.asAdmin()));
+ }
+
+ public default <E2> GraphTraversal<S, E2> mapKeys() {
+ return this.asAdmin().addStep(new MapKeysStep<>(this.asAdmin()));
+ }
+
/**
* Map the {@link Property} to its {@link Property#key}.
*
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b5186e28/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
index bb90d1e..9dfe2cb 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
@@ -252,6 +252,20 @@ public class __ {
}
/**
+ * @see {@link GraphTraversal#mapValues()}
+ */
+ public static <A, B> GraphTraversal<A, B> mapValues() {
+ return __.<A>start().mapValues();
+ }
+
+ /**
+ * @see {@link GraphTraversal#mapKeys()}
+ */
+ public static <A, B> GraphTraversal<A, B> mapKeys() {
+ return __.<A>start().mapKeys();
+ }
+
+ /**
* @see {@link GraphTraversal#key()}
*/
public static <A> GraphTraversal<A, String> key() {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b5186e28/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MapKeysStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MapKeysStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MapKeysStep.java
new file mode 100644
index 0000000..8aea53d
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MapKeysStep.java
@@ -0,0 +1,43 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one
+ * * or more contributor license agreements. See the NOTICE file
+ * * distributed with this work for additional information
+ * * regarding copyright ownership. The ASF licenses this file
+ * * to you under the Apache License, Version 2.0 (the
+ * * "License"); you may not use this file except in compliance
+ * * with the License. You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing,
+ * * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * * KIND, either express or implied. See the License for the
+ * * specific language governing permissions and limitations
+ * * under the License.
+ *
+ */
+
+package org.apache.tinkerpop.gremlin.process.traversal.step.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class MapKeysStep<S> extends FlatMapStep<Map<S, ?>, S> {
+
+ public MapKeysStep(final Traversal.Admin traversal) {
+ super(traversal);
+ }
+
+ @Override
+ protected Iterator<S> flatMap(final Traverser.Admin<Map<S, ?>> traverser) {
+ return traverser.get().keySet().iterator();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b5186e28/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MapValuesStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MapValuesStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MapValuesStep.java
new file mode 100644
index 0000000..fe41d15
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MapValuesStep.java
@@ -0,0 +1,43 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one
+ * * or more contributor license agreements. See the NOTICE file
+ * * distributed with this work for additional information
+ * * regarding copyright ownership. The ASF licenses this file
+ * * to you under the Apache License, Version 2.0 (the
+ * * "License"); you may not use this file except in compliance
+ * * with the License. You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing,
+ * * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * * KIND, either express or implied. See the License for the
+ * * specific language governing permissions and limitations
+ * * under the License.
+ *
+ */
+
+package org.apache.tinkerpop.gremlin.process.traversal.step.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class MapValuesStep<S> extends FlatMapStep<Map<?, S>, S> {
+
+ public MapValuesStep(final Traversal.Admin traversal) {
+ super(traversal);
+ }
+
+ @Override
+ protected Iterator<S> flatMap(final Traverser.Admin<Map<?, S>> traverser) {
+ return traverser.get().values().iterator();
+ }
+}
\ No newline at end of file
[2/2] incubator-tinkerpop git commit: JavaDoc JavaDoc JavaDoc -- so
tedious.
Posted by ok...@apache.org.
JavaDoc JavaDoc JavaDoc -- so tedious.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/2452a8cc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/2452a8cc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/2452a8cc
Branch: refs/heads/master
Commit: 2452a8cce89d78582257432670f38a70519fb2ca
Parents: 0a1861d
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Jun 30 09:56:48 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Jun 30 10:31:02 2015 -0600
----------------------------------------------------------------------
.../traversal/dsl/graph/GraphTraversal.java | 56 ++++++++++++++++----
1 file changed, 47 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2452a8cc/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
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 b69bcd4..80788bc 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
@@ -192,7 +192,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
}
/**
- * Map a traverser referencing an object of type <code>E</code> to an iterator of objects of type <code>E2</code>.
+ * Map a {@link Traverser} referencing an object of type <code>E</code> to an iterator of objects of type <code>E2</code>.
* The resultant iterator is drained one-by-one before a new <code>E</code> object is pulled in for processing.
*
* @param function the lambda expression that does the functional mapping
@@ -203,6 +203,14 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
return this.asAdmin().addStep(new LambdaFlatMapStep<>(this.asAdmin(), function));
}
+ /**
+ * Map a {@link Traverser} referencing an object of type <code>E</code> to an iterator of objects of type <code>E2</code>.
+ * The internal traversal is drained one-by-one before a new <code>E</code> object is pulled in for processing.
+ *
+ * @param flatMapTraversal the traversal generating objects of type <code>E2</code>
+ * @param <E2> the end type of the internal traversal
+ * @return the traversal with an appended {@link TraversalFlatMapStep}.
+ */
public default <E2> GraphTraversal<S, E2> flatMap(final Traversal<?, E2> flatMapTraversal) {
return this.asAdmin().addStep(new TraversalFlatMapStep<>(this.asAdmin(), flatMapTraversal));
}
@@ -478,6 +486,13 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
return this.asAdmin().addStep(new PathStep<>(this.asAdmin()));
}
+ /**
+ * Map the {@link Traverser} to a {@link Map} of bindings as specified by the provided match traversals.
+ *
+ * @param matchTraversals the traversal that maintain variables which must hold for the life of the traverser
+ * @param <E2> the type of the obejcts bound in the variables
+ * @return the traversal with an appended {@link MatchStep}.
+ */
public default <E2> GraphTraversal<S, Map<String, E2>> match(final Traversal<?, ?>... matchTraversals) {
return this.asAdmin().addStep(new MatchStep<>(this.asAdmin(), ConjunctionStep.Conjunction.AND, matchTraversals));
}
@@ -492,22 +507,39 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
return this.asAdmin().addStep(new SackStep<>(this.asAdmin()));
}
+ /**
+ * Map the {@link Traverser} to a {@link Map} projection of sideEffect values, map values, and/or path values.
+ *
+ * @param pop if there are multiple objects referenced in the path, the {@link Pop} to use.
+ * @param selectLabel1 the first key to project
+ * @param selectLabel2 the second key to project
+ * @param otherSelectLabels the third+ keys to project
+ * @param <E2> the type of the objects projected
+ * @return the traversal with an appended {@link SelectStep}.
+ */
public default <E2> GraphTraversal<S, Map<String, E2>> select(final Pop pop, final String selectLabel1, final String selectLabel2, String... otherSelectLabels) {
final String[] selectLabels = new String[otherSelectLabels.length + 2];
selectLabels[0] = selectLabel1;
selectLabels[1] = selectLabel2;
- for (int i = 0; i < otherSelectLabels.length; i++) {
- selectLabels[i + 2] = otherSelectLabels[i];
- }
+ System.arraycopy(otherSelectLabels, 0, selectLabels, 2, otherSelectLabels.length);
return this.asAdmin().addStep(new SelectStep<>(this.asAdmin(), pop, selectLabels));
}
+ /**
+ * Map the {@link Traverser} to a {@link Map} projection of sideEffect values, map values, and/or path values.
+ *
+ * @param selectLabel1 the first key to project
+ * @param selectLabel2 the second key to project
+ * @param otherSelectLabels the third+ keys to project
+ * @param <E2> the type of the objects projected
+ * @return the traversal with an appended {@link SelectStep}.
+ */
public default <E2> GraphTraversal<S, Map<String, E2>> select(final String selectLabel1, final String selectLabel2, String... otherSelectLabels) {
return this.select(null, selectLabel1, selectLabel2, otherSelectLabels);
}
public default <E2> GraphTraversal<S, E2> select(final Pop pop, final String selectLabel) {
- return this.asAdmin().addStep(new SelectOneStep(this.asAdmin(), pop, selectLabel));
+ return this.asAdmin().addStep(new SelectOneStep<>(this.asAdmin(), pop, selectLabel));
}
public default <E2> GraphTraversal<S, E2> select(final String selectLabel) {
@@ -781,6 +813,16 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
}
/**
+ * Once the first {@link Traverser} hits this step, a count down is started. Once the time limit is up, all remaining traversers are filtered out.
+ *
+ * @param timeLimit the count down time
+ * @return the traversal with an appended {@link TimeLimitStep}
+ */
+ public default GraphTraversal<S, E> timeLimit(final long timeLimit) {
+ return this.asAdmin().addStep(new TimeLimitStep<E>(this.asAdmin(), timeLimit));
+ }
+
+ /**
* Filter the <code>E</code> object if its {@link Traverser#path} is not {@link Path#isSimple}.
*
* @return the traversal with an appended {@link SimplePathStep}.
@@ -842,10 +884,6 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
return this.asAdmin().addStep(new GroupCountSideEffectStep<>(this.asAdmin(), sideEffectKey));
}
- public default GraphTraversal<S, E> timeLimit(final long timeLimit) {
- return this.asAdmin().addStep(new TimeLimitStep<E>(this.asAdmin(), timeLimit));
- }
-
public default GraphTraversal<S, E> tree(final String sideEffectKey) {
return this.asAdmin().addStep(new TreeSideEffectStep<>(this.asAdmin(), sideEffectKey));
}