You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2018/01/25 22:09:43 UTC
[1/6] tinkerpop git commit: TINKERPOP-1878 Added some Traversal
infrastructure
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1878 43ed0b969 -> 77daa5bc1
TINKERPOP-1878 Added some Traversal infrastructure
This is the start of getting Sparql working as a DSL in TinkerPop
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/5affca51
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/5affca51
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/5affca51
Branch: refs/heads/TINKERPOP-1878
Commit: 5affca51fddc185aaaeb0060493c745bd85d88a4
Parents: 43ed0b9
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jan 24 17:04:27 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jan 24 17:04:27 2018 -0500
----------------------------------------------------------------------
.../dsl/sparql/DefaultSparqlTraversal.java | 55 ++++++++
.../traversal/dsl/sparql/SparqlTraversal.java | 68 +++++++++
.../dsl/sparql/SparqlTraversalSource.java | 138 +++++++++++++++++++
.../traversal/strategy/SparqlStrategy.java | 25 ++++
4 files changed, 286 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5affca51/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/DefaultSparqlTraversal.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/DefaultSparqlTraversal.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/DefaultSparqlTraversal.java
new file mode 100644
index 0000000..133d4be
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/DefaultSparqlTraversal.java
@@ -0,0 +1,55 @@
+/*
+ * 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.sparql.process.traversal.dsl.sparql;
+
+import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class DefaultSparqlTraversal<S, E> extends DefaultTraversal<S, E> implements SparqlTraversal.Admin<S, E> {
+
+ public DefaultSparqlTraversal() {
+ super();
+ }
+
+ public DefaultSparqlTraversal(final SparqlTraversalSource sparqlTraversalSource) {
+ super(sparqlTraversalSource);
+ }
+
+ public DefaultSparqlTraversal(final Graph graph) {
+ super(graph);
+ }
+
+ @Override
+ public SparqlTraversal.Admin<S, E> asAdmin() {
+ return this;
+ }
+
+ @Override
+ public SparqlTraversal<S, E> iterate() {
+ return SparqlTraversal.Admin.super.iterate();
+ }
+
+ @Override
+ public DefaultSparqlTraversal<S, E> clone() {
+ return (DefaultSparqlTraversal<S, E>) super.clone();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5affca51/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
new file mode 100644
index 0000000..efa9489
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
@@ -0,0 +1,68 @@
+/*
+ * 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.sparql.process.traversal.dsl.sparql;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public interface SparqlTraversal<S, E> extends Traversal<S, E> {
+ public interface Admin<S, E> extends Traversal.Admin<S, E>, SparqlTraversal<S, E> {
+
+ @Override
+ public default <E2> SparqlTraversal.Admin<S, E2> addStep(final Step<?, E2> step) {
+ return (SparqlTraversal.Admin<S, E2>) Traversal.Admin.super.addStep((Step) step);
+ }
+
+ @Override
+ public default SparqlTraversal<S, E> iterate() {
+ return SparqlTraversal.super.iterate();
+ }
+
+ @Override
+ public SparqlTraversal.Admin<S, E> clone();
+ }
+
+ @Override
+ public default SparqlTraversal.Admin<S, E> asAdmin() {
+ return (SparqlTraversal.Admin<S, E>) this;
+ }
+
+ ////
+
+ /**
+ * Iterates the traversal presumably for the generation of side-effects.
+ */
+ @Override
+ public default SparqlTraversal<S, E> iterate() {
+ Traversal.super.iterate();
+ return this;
+ }
+
+ public static final class Symbols {
+
+ private Symbols() {
+ // static fields only
+ }
+
+ public static final String sparql = "sparql";
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5affca51/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
new file mode 100644
index 0000000..3596716
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
@@ -0,0 +1,138 @@
+/*
+ * 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.sparql.process.traversal.dsl.sparql;
+
+import org.apache.commons.configuration.Configuration;
+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.TraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.ConstantStep;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Transaction;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class SparqlTraversalSource implements TraversalSource {
+ protected transient RemoteConnection connection;
+ protected final Graph graph;
+ protected TraversalStrategies strategies;
+ protected Bytecode bytecode = new Bytecode();
+
+ public SparqlTraversalSource(final Graph graph, final TraversalStrategies traversalStrategies) {
+ this.graph = graph;
+ this.strategies = traversalStrategies;
+ }
+
+ public SparqlTraversalSource(final Graph graph) {
+ this(graph, TraversalStrategies.GlobalCache.getStrategies(graph.getClass()));
+ }
+
+ @Override
+ public TraversalStrategies getStrategies() {
+ return this.strategies;
+ }
+
+ @Override
+ public Graph getGraph() {
+ return this.graph;
+ }
+
+ @Override
+ public Bytecode getBytecode() {
+ return this.bytecode;
+ }
+
+ @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
+ public SparqlTraversalSource clone() {
+ try {
+ final SparqlTraversalSource clone = (SparqlTraversalSource) super.clone();
+ clone.strategies = this.strategies.clone();
+ clone.bytecode = this.bytecode.clone();
+ return clone;
+ } catch (final CloneNotSupportedException e) {
+ throw new IllegalStateException(e.getMessage(), e);
+ }
+ }
+
+ //// CONFIGURATIONS
+
+ @Override
+ public SparqlTraversalSource withStrategies(final TraversalStrategy... traversalStrategies) {
+ return (SparqlTraversalSource) TraversalSource.super.withStrategies(traversalStrategies);
+ }
+
+ @Override
+ @SuppressWarnings({"unchecked"})
+ public SparqlTraversalSource withoutStrategies(final Class<? extends TraversalStrategy>... traversalStrategyClasses) {
+ return (SparqlTraversalSource) TraversalSource.super.withoutStrategies(traversalStrategyClasses);
+ }
+
+ @Override
+ public SparqlTraversalSource withRemote(final Configuration conf) {
+ return (SparqlTraversalSource) TraversalSource.super.withRemote(conf);
+ }
+
+ @Override
+ public SparqlTraversalSource withRemote(final String configFile) throws Exception {
+ return (SparqlTraversalSource) TraversalSource.super.withRemote(configFile);
+ }
+
+ @Override
+ public SparqlTraversalSource withRemote(final RemoteConnection connection) {
+ try {
+ // check if someone called withRemote() more than once, so just release resources on the initial
+ // connection as you can't have more than one. maybe better to toss IllegalStateException??
+ if (this.connection != null)
+ this.connection.close();
+ } catch (Exception ignored) {
+ // not sure there's anything to do here
+ }
+
+ this.connection = connection;
+ final TraversalSource clone = this.clone();
+ clone.getStrategies().addStrategies(new RemoteStrategy(connection));
+ return (SparqlTraversalSource) clone;
+ }
+
+ public <S> SparqlTraversal<S,String> sparql(final String query) {
+ final SparqlTraversalSource clone = this.clone();
+ clone.bytecode.addStep(SparqlTraversal.Symbols.sparql, query);
+ final SparqlTraversal.Admin<S, S> traversal = new DefaultSparqlTraversal<>(clone);
+ return traversal.addStep(new ConstantStep<S,String>(traversal, query));
+ }
+
+ public Transaction tx() {
+ return this.graph.tx();
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (connection != null) connection.close();
+ }
+
+ @Override
+ public String toString() {
+ return StringFactory.traversalSourceString(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5affca51/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
new file mode 100644
index 0000000..6440127
--- /dev/null
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
@@ -0,0 +1,25 @@
+/*
+ * 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.sparql.process.traversal.strategy;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class SparqlStrategy {
+}
[4/6] tinkerpop git commit: TINKERPOP-1878 Minor javadoc and code
cleanup
Posted by sp...@apache.org.
TINKERPOP-1878 Minor javadoc and code cleanup
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/2977c41b
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/2977c41b
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/2977c41b
Branch: refs/heads/TINKERPOP-1878
Commit: 2977c41b46799ac4a80027af46803e4eb07aa6a9
Parents: 179127e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jan 25 15:36:53 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jan 25 15:36:53 2018 -0500
----------------------------------------------------------------------
.../process/traversal/dsl/sparql/SparqlTraversal.java | 12 +++---------
.../traversal/dsl/sparql/SparqlTraversalSource.java | 8 +++++++-
.../process/traversal/strategy/SparqlStrategy.java | 11 ++++++++---
3 files changed, 18 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2977c41b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
index efa9489..843267d 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversal.java
@@ -22,6 +22,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.Step;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
/**
+ * The {@code SparqlTraversal} has no additional traversal steps. The only step available for "SPARQL" is the
+ * {@link SparqlTraversalSource#sparql(String)} start step.
+ *
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public interface SparqlTraversal<S, E> extends Traversal<S, E> {
@@ -56,13 +59,4 @@ public interface SparqlTraversal<S, E> extends Traversal<S, E> {
Traversal.super.iterate();
return this;
}
-
- public static final class Symbols {
-
- private Symbols() {
- // static fields only
- }
-
- public static final String sparql = "sparql";
- }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2977c41b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
index 3596716..b156ed1 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
@@ -25,12 +25,15 @@ import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
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.step.map.ConstantStep;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Transaction;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
/**
+ * A {@link TraversalSource} implementation that spawns {@link SparqlTraversal} instances.
+ *
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public class SparqlTraversalSource implements TraversalSource {
@@ -115,9 +118,12 @@ public class SparqlTraversalSource implements TraversalSource {
return (SparqlTraversalSource) clone;
}
+ /**
+ * The start step for a SPARQL based traversal that accepts a string representation of the query to execute.
+ */
public <S> SparqlTraversal<S,String> sparql(final String query) {
final SparqlTraversalSource clone = this.clone();
- clone.bytecode.addStep(SparqlTraversal.Symbols.sparql, query);
+ clone.bytecode.addStep(GraphTraversal.Symbols.constant, query);
final SparqlTraversal.Admin<S, S> traversal = new DefaultSparqlTraversal<>(clone);
return traversal.addStep(new ConstantStep<S,String>(traversal, query));
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2977c41b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
index 07ac4cf..bb0b326 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
@@ -22,17 +22,22 @@ import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decorati
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.ConstantStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.map.TraversalMapStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import org.apache.tinkerpop.gremlin.sparql.SparqlToGremlinCompiler;
+import org.apache.tinkerpop.gremlin.sparql.process.traversal.dsl.sparql.SparqlTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import java.util.Collections;
import java.util.Set;
/**
+ * This {@link TraversalStrategy} is used in conjunction with the {@link SparqlTraversalSource} which has a single
+ * {@code sparql()} start step. That step adds a {@link ConstantStep} to the traversal with the SPARQL query within
+ * it as a string value. This strategy finds that step and transpiles it to a Gremlin traversal which then replaces
+ * the {@link ConstantStep}.
+ *
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.DecorationStrategy>
@@ -69,11 +74,11 @@ public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.
sparqlTraversal.asAdmin().getSteps().forEach(s -> traversal.addStep(s));
} else {
// The ConstantStep expects a string value
- throw new IllegalStateException("SparqlStrategy cannot be applied to this traversal");
+ throw new IllegalStateException("SparqlStrategy cannot be applied to a traversal that does not consist of a single ConstantStep<?,String>");
}
} else {
// SparqlStrategy requires that there be one step and it be a ConstantStep that contains some SPARQL
- throw new IllegalStateException("SparqlStrategy cannot be applied to this traversal");
+ throw new IllegalStateException("SparqlStrategy cannot be applied to a traversal that does not consist of a single ConstantStep<?,String>");
}
}
}
[2/6] tinkerpop git commit: TINKERPOP-1878 Added a basics for sparql
execution in a traversal
Posted by sp...@apache.org.
TINKERPOP-1878 Added a basics for sparql execution in a traversal
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/019bc232
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/019bc232
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/019bc232
Branch: refs/heads/TINKERPOP-1878
Commit: 019bc2329d0b7a6d4c4bc52279a456fd039c40ac
Parents: 5affca5
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jan 25 14:46:31 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jan 25 14:46:31 2018 -0500
----------------------------------------------------------------------
.../traversal/step/map/ConstantStep.java | 4 ++
.../traversal/strategy/SparqlStrategy.java | 56 +++++++++++++++++++-
.../dsl/sparql/SparqlTraversalSourceTest.java | 39 ++++++++++++++
.../src/test/resources/log4j-silent.properties | 23 ++++++++
.../src/test/resources/log4j-test.properties | 23 ++++++++
5 files changed, 144 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/019bc232/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ConstantStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ConstantStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ConstantStep.java
index 5d02e28..749de31 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ConstantStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ConstantStep.java
@@ -36,6 +36,10 @@ public class ConstantStep<S, E> extends MapStep<S, E> {
this.constant = constant;
}
+ public E getConstant() {
+ return this.constant;
+ }
+
@Override
protected E map(final Traverser.Admin<S> traverser) {
return this.constant;
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/019bc232/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
index 6440127..07ac4cf 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
@@ -18,8 +18,62 @@
*/
package org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.ConstantStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.TraversalMapStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.apache.tinkerpop.gremlin.sparql.SparqlToGremlinCompiler;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+import java.util.Collections;
+import java.util.Set;
+
/**
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
-public class SparqlStrategy {
+public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.DecorationStrategy>
+ implements TraversalStrategy.DecorationStrategy {
+ private static final SparqlStrategy INSTANCE = new SparqlStrategy();
+
+ private static final Set<Class<? extends DecorationStrategy>> POSTS = Collections.singleton(VertexProgramStrategy.class);
+
+ private SparqlStrategy() {}
+
+ public static SparqlStrategy instance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public Set<Class<? extends DecorationStrategy>> applyPost() {
+ return POSTS;
+ }
+
+
+ @Override
+ public void apply(final Traversal.Admin<?, ?> traversal) {
+ if (!(traversal.getParent() instanceof EmptyStep))
+ return;
+
+ if (traversal.getSteps().size() == 1 && traversal.getEndStep() instanceof ConstantStep) {
+ final ConstantStep stepWithSparql = (ConstantStep) traversal.getEndStep();
+ final Object constant = stepWithSparql.getConstant();
+ if (constant instanceof String) {
+ final String sparql = (String) constant;
+ final Traversal<Vertex, ?> sparqlTraversal = SparqlToGremlinCompiler.convertToGremlinTraversal(
+ traversal.getGraph().get(), sparql);
+ TraversalHelper.removeAllSteps(traversal);
+ sparqlTraversal.asAdmin().getSteps().forEach(s -> traversal.addStep(s));
+ } else {
+ // The ConstantStep expects a string value
+ throw new IllegalStateException("SparqlStrategy cannot be applied to this traversal");
+ }
+ } else {
+ // SparqlStrategy requires that there be one step and it be a ConstantStep that contains some SPARQL
+ throw new IllegalStateException("SparqlStrategy cannot be applied to this traversal");
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/019bc232/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
new file mode 100644
index 0000000..9e5ffc0
--- /dev/null
+++ b/sparql-gremlin/src/test/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSourceTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.sparql.process.traversal.dsl.sparql;
+
+import org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy.SparqlStrategy;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
+import org.junit.Test;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class SparqlTraversalSourceTest {
+
+ @Test
+ public void shouldDoStuff() {
+ final Graph graph = TinkerFactory.createModern();
+ final SparqlTraversalSource g = graph.traversal(SparqlTraversalSource.class).
+ withStrategies(SparqlStrategy.instance());
+ final Object x = g.sparql("SELECT ?name ?age WHERE { ?person v:name ?name . ?person v:age ?age }").toList();
+ System.out.println(x);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/019bc232/sparql-gremlin/src/test/resources/log4j-silent.properties
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/resources/log4j-silent.properties b/sparql-gremlin/src/test/resources/log4j-silent.properties
new file mode 100644
index 0000000..1825bb0
--- /dev/null
+++ b/sparql-gremlin/src/test/resources/log4j-silent.properties
@@ -0,0 +1,23 @@
+# 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.
+
+# this file should always have logging set to OFF. it seems, however, that an appender of some sort is
+# required or else some logs throw error and use other log4j.properties files on the path.
+log4j.rootLogger=OFF, stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%p] %C - %m%n
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/019bc232/sparql-gremlin/src/test/resources/log4j-test.properties
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/test/resources/log4j-test.properties b/sparql-gremlin/src/test/resources/log4j-test.properties
new file mode 100644
index 0000000..79038b1
--- /dev/null
+++ b/sparql-gremlin/src/test/resources/log4j-test.properties
@@ -0,0 +1,23 @@
+#
+# 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.
+#
+
+log4j.rootLogger=WARN, stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%p] %C - %m%n
\ No newline at end of file
[6/6] tinkerpop git commit: TINKERPOP-1878 Updates to changelog and
code comments
Posted by sp...@apache.org.
TINKERPOP-1878 Updates to changelog and code comments
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/77daa5bc
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/77daa5bc
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/77daa5bc
Branch: refs/heads/TINKERPOP-1878
Commit: 77daa5bc1f9169bce89e287354da806b3b6bd028
Parents: b94866a
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jan 25 17:09:17 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jan 25 17:09:17 2018 -0500
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../process/traversal/dsl/sparql/SparqlTraversalSource.java | 6 ++++++
2 files changed, 7 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/77daa5bc/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 0716c8e..0c0b3b1 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -27,6 +27,7 @@ This release also includes changes from <<release-3-2-8, 3.2.8>>.
* Fixed regression issue where the HTTPChannelizer doesn't instantiate the specified AuthenticationHandler
* Defaulted GLV tests for gremlin-python to run for GraphSON 3.0.
+* Fixed a bug in dynamic Gryo registration where registrations that did not have serializers would fail.
* In gremlin-python, the GraphSON 3.0 `g:Set` type is now deserialized to `List`.
[[release-3-3-1]]
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/77daa5bc/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
index 3889d95..deb16f7 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
@@ -124,6 +124,12 @@ public class SparqlTraversalSource implements TraversalSource {
*/
public <S> SparqlTraversal<S,String> sparql(final String query) {
final SparqlTraversalSource clone = this.clone();
+
+ // this is a bit of a hack to get remote traversals to work cleanly. on the remote side, we'd expect a
+ // GraphTraversalSource not a SparqlTraversalSource (given that sparql-gremlin is to be implemented in the
+ // DSL pattern). Instead of just sending the constant() step with the sparql query we also include an
+ // inject() step which will be recognized by a GraphTraversalSource on the remote side. Since SparqlStrategy
+ // wholly replaces both of these steps, the traversal bytecode can be read properly.
clone.bytecode.addStep(GraphTraversal.Symbols.inject);
clone.bytecode.addStep(GraphTraversal.Symbols.constant, query);
final SparqlTraversal.Admin<S, S> traversal = new DefaultSparqlTraversal<>(clone);
[3/6] tinkerpop git commit: TINKERPOP-1878 Dropped the console app
Posted by sp...@apache.org.
TINKERPOP-1878 Dropped the console app
This allows TinkerGraph to remain a test dependency only and the console app was more of a test rig than something that a user of this library would use, so it seemed like something that could be dropped.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/179127ee
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/179127ee
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/179127ee
Branch: refs/heads/TINKERPOP-1878
Commit: 179127eea642805c97f55abf3d45a3f1e9e4f671
Parents: 019bc23
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jan 25 14:49:18 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jan 25 14:49:18 2018 -0500
----------------------------------------------------------------------
sparql-gremlin/pom.xml | 1 +
.../gremlin/sparql/ConsoleCompiler.java | 165 -------------------
2 files changed, 1 insertion(+), 165 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/179127ee/sparql-gremlin/pom.xml
----------------------------------------------------------------------
diff --git a/sparql-gremlin/pom.xml b/sparql-gremlin/pom.xml
index d38a85d..0dceb85 100644
--- a/sparql-gremlin/pom.xml
+++ b/sparql-gremlin/pom.xml
@@ -42,6 +42,7 @@
<groupId>org.apache.tinkerpop</groupId>
<artifactId>tinkergraph-gremlin</artifactId>
<version>${project.version}</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tinkerpop</groupId>
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/179127ee/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/ConsoleCompiler.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/ConsoleCompiler.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/ConsoleCompiler.java
deleted file mode 100644
index 0d50475..0000000
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/ConsoleCompiler.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * 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.sparql;
-
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.DefaultParser;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.tinkerpop.gremlin.jsr223.JavaTranslator;
-import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.io.IoCore;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
-
-import org.apache.tinkerpop.gremlin.sparql.SparqlToGremlinCompiler;
-
-class ConsoleCompiler {
-
- public static void main(final String[] args) throws IOException {
- //args = "/examples/modern1.sparql";
- final Options options = new Options();
- options.addOption("f", "file", true, "a file that contains a SPARQL query");
- options.addOption("g", "graph", true, "the graph that's used to execute the query [classic|modern|crew|kryo file]");
- // TODO: add an OLAP option (perhaps: "--olap spark"?)
-
- final CommandLineParser parser = new DefaultParser();
- final CommandLine commandLine;
-
- try {
- commandLine = parser.parse(options, args);
- } catch (ParseException e) {
- System.out.println(e.getMessage());
- printHelp(1);
- return;
- }
-
- final InputStream inputStream = commandLine.hasOption("file")
- ? new FileInputStream(commandLine.getOptionValue("file"))
- : System.in;
- final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
- final StringBuilder queryBuilder = new StringBuilder();
-
- if (!reader.ready()) {
- printHelp(1);
- }
-
- String line;
- while (null != (line = reader.readLine())) {
- queryBuilder.append(System.lineSeparator()).append(line);
- }
-
- final String queryString = queryBuilder.toString();
- Graph graph;
-
- if (commandLine.hasOption("graph")) {
- switch (commandLine.getOptionValue("graph").toLowerCase()) {
- case "classic":
- graph = TinkerFactory.createClassic();
- break;
- case "modern":
- graph = TinkerFactory.createModern();
- System.out.println("Modern Graph Created");
- break;
- case "crew":
- graph = TinkerFactory.createTheCrew();
- break;
- default:
- graph = TinkerGraph.open();
- System.out.println("Graph Created");
- String graphName = commandLine.getOptionValue("graph");
- long startTime= System.currentTimeMillis();
- if(graphName.endsWith(".graphml"))
- graph.io(IoCore.graphml()).readGraph(graphName);
- else if(graphName.endsWith(".kryo")||graphName.endsWith("gryo"))
- graph.io(IoCore.gryo()).readGraph(graphName);
- long endTime = System.currentTimeMillis();
- System.out.println("Time taken to load graph from kyro file: "+ (endTime-startTime)+" mili seconds");
- break;
- }
- } else {
-
- graph = TinkerFactory.createModern();
- }
-
- long startTime = System.currentTimeMillis();
- final Traversal<Vertex, ?> traversal = SparqlToGremlinCompiler.convertToGremlinTraversal(graph, queryString);
- long endTime = System.currentTimeMillis();
- System.out.println("Time traken to convert SPARQL to Gremlin Traversal : "+ (endTime - startTime)+ " miliseconds");
-
- printWithHeadline("SPARQL Query", queryString);
- // printWithHeadline("Traversal (prior execution)", traversal);
-
-
- Bytecode traversalByteCode = traversal.asAdmin().getBytecode();
-
-
-// JavaTranslator.of(graph.traversal()).translate(traversalByteCode);
-//
-// System.out.println("the Byte Code : "+ traversalByteCode.toString());
- printWithHeadline("Result", String.join(System.lineSeparator(),JavaTranslator.of(graph.traversal()).translate(traversalByteCode).toStream().map(Object::toString).collect(Collectors.toList())));
- // printWithHeadline("Traversal (after execution)", traversal);
- }
-
- private static void printHelp(final int exitCode) throws IOException {
- final Map<String, String> env = System.getenv();
- final String command = env.containsKey("LAST_COMMAND") ? env.get("LAST_COMMAND") : "sparql-gremlin.sh";
- printWithHeadline("Usage Examples", String.join("\n",
- command + " -f examples/modern1.sparql",
- command + " < examples/modern2.sparql",
- command + " <<< 'SELECT * WHERE { ?a e:knows ?b }'",
- command + " -g crew < examples/crew1.sparql"));
- if (exitCode >= 0) {
- System.exit(exitCode);
- }
- }
-
- private static void printWithHeadline(final String headline, final Object content) throws IOException {
- final StringReader sr = new StringReader(content != null ? content.toString() : "null");
- final BufferedReader br = new BufferedReader(sr);
- String line;
- System.out.println();
- System.out.println( headline );
- System.out.println();
- boolean skip = true;
- while (null != (line = br.readLine())) {
- skip &= line.isEmpty();
- if (!skip) {
- System.out.println(" " + line);
- }
- }
- System.out.println();
- br.close();
- sr.close();
- }
-}
[5/6] tinkerpop git commit: TINKERPOP-1878 sparql() step works over
remoting
Posted by sp...@apache.org.
TINKERPOP-1878 sparql() step works over remoting
At this point it is only tested to work with Gryo 3.0. Fixed a bug with how dynamic gryo registrations work - they failed if you didn't have a specific serializer specified. Introduced a bit of a hack to make SparqlTraversalSource behave like a GraphTraversalSource and thus more cleanly follow the DSL pattern. Not sure if that's a great approach yet or not, but it seems harmless at this point.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b94866aa
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b94866aa
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b94866aa
Branch: refs/heads/TINKERPOP-1878
Commit: b94866aa8c6b687c656a5ead04e5125fa980ceca
Parents: 2977c41
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jan 25 17:00:54 2018 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jan 25 17:00:54 2018 -0500
----------------------------------------------------------------------
.../apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java | 5 ++++-
sparql-gremlin/pom.xml | 4 ----
.../process/traversal/dsl/sparql/SparqlTraversalSource.java | 3 +++
.../sparql/process/traversal/strategy/SparqlStrategy.java | 5 +++--
4 files changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b94866aa/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
index fc39cb0..d32bdfd 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
@@ -380,6 +380,9 @@ public enum GryoVersion {
"org.apache.tinkerpop.gremlin.driver.ser.RequestMessageGryoSerializer", 167);
tryAddDynamicType(this, "org.apache.tinkerpop.gremlin.driver.message.ResponseMessage",
"org.apache.tinkerpop.gremlin.driver.ser.ResponseMessageGryoSerializer", 169);
+
+ tryAddDynamicType(this, "org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy.SparqlStrategy",
+ null, 1690);
}};
}
@@ -555,7 +558,7 @@ public enum GryoVersion {
final String serializer, final int registrationId) {
try {
final Class typeClass = Class.forName(type);
- final Optional<SerializerShim<?>> serializerInstance = Optional.of(serializer)
+ final Optional<SerializerShim<?>> serializerInstance = Optional.ofNullable(serializer)
.map(FunctionUtils.wrapFunction(Class::forName))
.map(FunctionUtils.wrapFunction(c -> (SerializerShim<?>) c.getConstructor().newInstance()));
if (serializerInstance.isPresent()) {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b94866aa/sparql-gremlin/pom.xml
----------------------------------------------------------------------
diff --git a/sparql-gremlin/pom.xml b/sparql-gremlin/pom.xml
index 0dceb85..0e3da38 100644
--- a/sparql-gremlin/pom.xml
+++ b/sparql-gremlin/pom.xml
@@ -11,10 +11,6 @@
<artifactId>sparql-gremlin</artifactId>
<name>Apache TinkerPop :: SPARQL Gremlin</name>
- <properties>
- <query.dir>src/test/resources/sparql/queries</query.dir>
- </properties>
-
<dependencies>
<dependency>
<groupId>org.apache.jena</groupId>
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b94866aa/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
index b156ed1..3889d95 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/dsl/sparql/SparqlTraversalSource.java
@@ -27,6 +27,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
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.step.map.ConstantStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.InjectStep;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Transaction;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
@@ -123,8 +124,10 @@ public class SparqlTraversalSource implements TraversalSource {
*/
public <S> SparqlTraversal<S,String> sparql(final String query) {
final SparqlTraversalSource clone = this.clone();
+ clone.bytecode.addStep(GraphTraversal.Symbols.inject);
clone.bytecode.addStep(GraphTraversal.Symbols.constant, query);
final SparqlTraversal.Admin<S, S> traversal = new DefaultSparqlTraversal<>(clone);
+ traversal.addStep(new InjectStep<S>(traversal));
return traversal.addStep(new ConstantStep<S,String>(traversal, query));
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b94866aa/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
----------------------------------------------------------------------
diff --git a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
index bb0b326..d74ac3e 100644
--- a/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
+++ b/sparql-gremlin/src/main/java/org/apache/tinkerpop/gremlin/sparql/process/traversal/strategy/SparqlStrategy.java
@@ -19,6 +19,7 @@
package org.apache.tinkerpop.gremlin.sparql.process.traversal.strategy;
import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy;
+import org.apache.tinkerpop.gremlin.process.remote.traversal.strategy.decoration.RemoteStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.ConstantStep;
@@ -44,7 +45,7 @@ public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.
implements TraversalStrategy.DecorationStrategy {
private static final SparqlStrategy INSTANCE = new SparqlStrategy();
- private static final Set<Class<? extends DecorationStrategy>> POSTS = Collections.singleton(VertexProgramStrategy.class);
+ private static final Set<Class<? extends DecorationStrategy>> POSTS = Collections.singleton(RemoteStrategy.class);
private SparqlStrategy() {}
@@ -63,7 +64,7 @@ public class SparqlStrategy extends AbstractTraversalStrategy<TraversalStrategy.
if (!(traversal.getParent() instanceof EmptyStep))
return;
- if (traversal.getSteps().size() == 1 && traversal.getEndStep() instanceof ConstantStep) {
+ if (traversal.getSteps().size() == 2 && traversal.getEndStep() instanceof ConstantStep) {
final ConstantStep stepWithSparql = (ConstantStep) traversal.getEndStep();
final Object constant = stepWithSparql.getConstant();
if (constant instanceof String) {