From 7bae7bddabeeecbe02cd3c05976bd0628450c876 Mon Sep 17 00:00:00 2001 From: Dwitry Date: Fri, 18 Jan 2019 17:22:04 +0200 Subject: [PATCH] Revert #218 as support was removed on Neptune - Document specific Signed-off-by: Dwitry dwitry@users.noreply.github.com --- .../gremlin/groups/SkipWithNeptune.java | 11 ++++++++ .../gremlin/queries/SpecificsTest.java | 28 ++++++++++++++++++- .../ir/rewrite/NeptuneFlavor.scala | 10 +++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/testware/integration-tests/src/test/java/org/opencypher/gremlin/groups/SkipWithNeptune.java b/testware/integration-tests/src/test/java/org/opencypher/gremlin/groups/SkipWithNeptune.java index 2822fe6e..a3126324 100644 --- a/testware/integration-tests/src/test/java/org/opencypher/gremlin/groups/SkipWithNeptune.java +++ b/testware/integration-tests/src/test/java/org/opencypher/gremlin/groups/SkipWithNeptune.java @@ -34,6 +34,17 @@ public interface SkipWithNeptune { interface Limit0 extends SkipWithNeptune { } + /** + * Unable to start traversal with `.inject` step. + * error message : no viable alternative at input 'g.inject' + * + * @see SpecificsTest#gInjectGremlin() + * @see SpecificsTest#gInject() + * @see NeptuneFlavor#injectWorkaround(Seq) Workaround + */ + interface gInject extends SkipWithNeptune { + } + /** * Count step traversal is not aliased. * diff --git a/testware/integration-tests/src/test/java/org/opencypher/gremlin/queries/SpecificsTest.java b/testware/integration-tests/src/test/java/org/opencypher/gremlin/queries/SpecificsTest.java index 27c6180c..e263e537 100644 --- a/testware/integration-tests/src/test/java/org/opencypher/gremlin/queries/SpecificsTest.java +++ b/testware/integration-tests/src/test/java/org/opencypher/gremlin/queries/SpecificsTest.java @@ -55,7 +55,7 @@ private List> submitAndGet(String cypher) { public void return100Elements() throws Exception { Client client = gremlinServer.gremlinClient(); - client.submit("g.inject(1).times(100).repeat(addV().property('the_property', 'the_value'))").all().get(); + client.submit("g.V().limit(0).inject(1).times(100).repeat(addV().property('the_property', 'the_value'))").all().get(); List results = client.submit("g.V()").all().get(); @@ -226,4 +226,30 @@ public void noExceptionDetailMessage() throws Exception { assertThatThrownBy(() -> client.submit("g.inject(1).math('_ / 0')").all().get()) .hasMessageContaining("Division by zero"); } + + /** + * @see #gInject() + */ + @Test + @Category(SkipWithNeptune.gInject.class) + public void gInjectGremlin() throws Exception { + Client client = gremlinServer.gremlinClient(); + + String test = client.submit("g.inject('test')").one().getString(); + + assertThat(test).isEqualTo("test"); + } + + /** + * @see NeptuneFlavor#injectWorkaround(Seq) + */ + @Test + public void gInject() throws Exception { + List> results = submitAndGet("RETURN 'test' as r"); + + assertThat(results) + .extracting("r") + .containsExactly("test"); + } + } diff --git a/translation/src/main/scala/org/opencypher/gremlin/translation/ir/rewrite/NeptuneFlavor.scala b/translation/src/main/scala/org/opencypher/gremlin/translation/ir/rewrite/NeptuneFlavor.scala index 3c1ae5fb..0d38d5b4 100644 --- a/translation/src/main/scala/org/opencypher/gremlin/translation/ir/rewrite/NeptuneFlavor.scala +++ b/translation/src/main/scala/org/opencypher/gremlin/translation/ir/rewrite/NeptuneFlavor.scala @@ -26,6 +26,7 @@ import org.opencypher.gremlin.translation.ir.model.{GremlinStep, _} object NeptuneFlavor extends GremlinRewriter { override def apply(steps: Seq[GremlinStep]): Seq[GremlinStep] = { Seq( + injectWorkaround(_), limit0Workaround(_), multipleLabelsWorkaround(_), aggregateWithSameNameWorkaround(_), @@ -80,6 +81,15 @@ object NeptuneFlavor extends GremlinRewriter { })(bySteps) } + private def injectWorkaround(steps: Seq[GremlinStep]): Seq[GremlinStep] = { + steps match { + case Inject(s) :: rest => + Vertex :: Limit(0) :: Inject(s) :: rest + case _ => + steps + } + } + private def limit0Workaround(steps: Seq[GremlinStep]): Seq[GremlinStep] = { replace({ case Barrier :: Limit(0) :: rest =>