Skip to content

Commit

Permalink
handle inject with nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentyn Kahamlyk authored and Valentyn Kahamlyk committed Jun 27, 2024
1 parent 4f8b394 commit 15cc91e
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/
package org.apache.tinkerpop.gremlin.language.translator;

import org.antlr.v4.runtime.ParserRuleContext;
import org.apache.tinkerpop.gremlin.language.grammar.GremlinParser;
import org.apache.tinkerpop.gremlin.language.grammar.GremlinParser.GenericLiteralVarargsContext;
import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex;

/**
Expand Down Expand Up @@ -119,10 +121,11 @@ public Void visitFloatLiteral(final GremlinParser.FloatLiteralContext ctx) {

@Override
public Void visitInfLiteral(final GremlinParser.InfLiteralContext ctx) {
if (ctx.SignedInfLiteral().getText().equals("-Infinity"))
if (ctx.SignedInfLiteral().getText().equals("-Infinity")) {
sb.append("Double.NEGATIVE_INFINITY");
else
} else {
sb.append("Double.POSITIVE_INFINITY");
}
return null;
}

Expand All @@ -136,4 +139,42 @@ public Void visitNullLiteral(final GremlinParser.NullLiteralContext ctx) {
sb.append(ctx.getText());
return null;
}

@Override
public Void visitTraversalSourceSpawnMethod_inject(final GremlinParser.TraversalSourceSpawnMethod_injectContext ctx) {
return handleInject(ctx);
}

@Override
public Void visitTraversalMethod_inject(final GremlinParser.TraversalMethod_injectContext ctx) {
return handleInject(ctx);
}

private Void handleInject(final ParserRuleContext ctx) {
// very special handling for inject with second `null` argument like g.inject(1, null)
// gremlin-groovy cannot work correctly with such type of queries
if (ctx.getChildCount() > 3 && ctx.getChild(2) instanceof GenericLiteralVarargsContext) {
final GenericLiteralVarargsContext varArgs = (GenericLiteralVarargsContext) ctx.getChild(2);
if (varArgs.getChildCount() > 2 && "null".equals(varArgs.getChild(2).getText())) {
sb.append(ctx.getChild(0).getText());
sb.append("(");
for (int i = 0; i < varArgs.getChildCount(); i += 2) {
if (i == 2) {
sb.append("(Object) null");
} else {
visit(varArgs.getChild(i));
}

if (i < varArgs.getChildCount() - 1) {
sb.append(", ");
}
}

sb.append(")");
return null;
}
}

return visitChildren(ctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

@RunWith(Cucumber.class)
@CucumberOptions(
tags = "not @RemoteOnly and not @GraphComputerOnly and not @AllowNullPropertyValues and not @GremlinLangOnly",
tags = "not @RemoteOnly and not @GraphComputerOnly and not @AllowNullPropertyValues",
glue = { "org.apache.tinkerpop.gremlin.features" },
objectFactory = GraphBinaryGroovyRemoteFeatureTest.RemoteGuiceFactory.class,
features = { "classpath:/org/apache/tinkerpop/gremlin/test/features" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.PathTest",
method = "g_injectX1_null_nullX_path_dedup",
reason = "The inject() step is not supported by GraphComputer")
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchTest",
method = "*",
reason = "MatchAlgorithmStrategy construction doesn't work for gremlin-groovy")
@GraphProvider.Descriptor(computer = TinkerGraphComputer.class)
public class GraphBinaryRemoteGraphComputerProvider extends AbstractRemoteGraphProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ public Settings overrideSettings(final Settings settings) {
return settings;
}

@Test
public void playTest() {
final Cluster cluster = TestClientFactory.build().create();
try {
final GraphTraversalSource g = traversal().with(DriverRemoteConnection.using(cluster));

final Object result = g.with("language", "groovy-test").inject(null, null).toList().get(0);
assertNull(result);
} catch (Exception ex) {
throw ex;
} finally {
cluster.close();
}
}

@Test
public void shouldSubmitScriptWithGraphBinary() throws Exception {
final Cluster cluster = TestClientFactory.build().create();
Expand Down Expand Up @@ -555,9 +570,8 @@ public void shouldSubmitTraversalInGremlinLang() {
try {
final GraphTraversalSource g = traversal().with(DriverRemoteConnection.using(cluster));

// this query doesn't work in gremlin-groovy
final Object result = g.with("language", "gremlin-lang").inject(null, null).toList().get(0);
assertNull(result);
final List result = g.with("language", "gremlin-lang").inject(null, null).inject(null, null).toList();
assertEquals(4, result.size());
} catch (Exception ex) {
throw ex;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ public class ProcessComputerSuite extends AbstractGremlinSuite {
GraphTest.Traversals.class,
LoopsTest.Traversals.class,
MapTest.Traversals.class,
// MatchTest.CountMatchTraversals.class,
// MatchTest.GreedyMatchTraversals.class,
MatchTest.CountMatchTraversals.class,
MatchTest.GreedyMatchTraversals.class,
MathTest.Traversals.class,
MaxTest.Traversals.class,
MeanTest.Traversals.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class ProcessLimitedComputerSuite extends AbstractGremlinSuite {
*/
private static final Class<?>[] allTests = new Class<?>[]{
GraphComputerTest.class,
// MatchTest.CountMatchTraversals.class,
// MatchTest.GreedyMatchTraversals.class,
MatchTest.CountMatchTraversals.class,
MatchTest.GreedyMatchTraversals.class,
ProfileTest.Traversals.class,
ProgramTest.Traversals.class,
WriteTest.Traversals.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionTest;
import org.apache.tinkerpop.gremlin.process.traversal.step.ComplexTest;
import org.apache.tinkerpop.gremlin.process.traversal.step.TernaryBooleanLogicsTest;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchTest;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MergeEdgeTest;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MergeVertexTest;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.ProfileTest;
Expand Down Expand Up @@ -58,8 +59,8 @@ public class ProcessLimitedStandardSuite extends AbstractGremlinSuite {
MergeVertexTest.Traversals.class,
MergeEdgeTest.Traversals.class,

// MatchTest.CountMatchTraversals.class,
// MatchTest.GreedyMatchTraversals.class,
MatchTest.CountMatchTraversals.class,
MatchTest.GreedyMatchTraversals.class,
ProfileTest.Traversals.class,
WriteTest.Traversals.class,
ExplainTest.Traversals.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ Feature: Step - inject()
| m[{"name":"marko", "age":null}] |

@GraphComputerVerificationInjectionNotSupported
@GremlinLangOnly # bug in implementation for gremlin-groovy
Scenario: g_injectXnull_nullX
Given the modern graph
And the traversal of
Expand Down Expand Up @@ -149,7 +148,6 @@ Feature: Step - inject()
Then the result should be empty

@GraphComputerVerificationInjectionNotSupported
@GremlinLangOnly # bug in implementation for gremlin-groovy
Scenario: g_VX1X_valuesXageX_injectXnull_nullX
Given the modern graph
And using the parameter xx1 defined as "v[marko].id"
Expand Down

0 comments on commit 15cc91e

Please sign in to comment.