From 6a8d0de3d7c2eb1798f3182909b70089ec2a3837 Mon Sep 17 00:00:00 2001 From: Cole-Greer Date: Wed, 27 Nov 2024 17:43:15 -0800 Subject: [PATCH] fix failing feature tests --- .../grammar/TraversalMethodVisitor.java | 2 ++ .../TraversalSourceSpawnMethodVisitor.java | 4 +++ .../traversal/dsl/graph/GraphTraversal.java | 27 +++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitor.java index 55c74aeea8..d9c4702a5e 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitor.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalMethodVisitor.java @@ -143,6 +143,8 @@ public GraphTraversal visitTraversalMethod_mergeE_Map(final GremlinParser.Traver final Object literalOrVar = antlr.argumentVisitor.visitGenericLiteralMapNullableArgument(ctx.genericLiteralMapNullableArgument()); if (GValue.valueInstanceOf(literalOrVar, GType.MAP)) return graphTraversal.mergeE((GValue>) literalOrVar); + else if (GValue.valueInstanceOf(literalOrVar, GType.UNKNOWN) && ((GValue) literalOrVar).get() == null) + return graphTraversal.mergeE(GValue.ofMap(((GValue) literalOrVar).getName(), null)); else return graphTraversal.mergeE((Map) literalOrVar); } diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSpawnMethodVisitor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSpawnMethodVisitor.java index c65b283b0a..4c57cd4a67 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSpawnMethodVisitor.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalSourceSpawnMethodVisitor.java @@ -134,6 +134,8 @@ public GraphTraversal visitTraversalSourceSpawnMethod_mergeV_Map(final GremlinPa final Object literalOrVar = antlr.argumentVisitor.visitGenericLiteralMapNullableArgument(ctx.genericLiteralMapNullableArgument()); if (GValue.valueInstanceOf(literalOrVar, GType.MAP)) return this.traversalSource.mergeV((GValue) literalOrVar); + else if (GValue.valueInstanceOf(literalOrVar, GType.UNKNOWN) && ((GValue) literalOrVar).get() == null) + return this.traversalSource.mergeV((GValue) GValue.ofMap(((GValue) literalOrVar).getName(), null)); else return this.traversalSource.mergeV((Map) literalOrVar); } @@ -162,6 +164,8 @@ public GraphTraversal visitTraversalSourceSpawnMethod_mergeE_Map(final GremlinPa final Object literalOrVar = antlr.argumentVisitor.visitGenericLiteralMapNullableArgument(ctx.genericLiteralMapNullableArgument()); if (GValue.valueInstanceOf(literalOrVar, GType.MAP)) return this.traversalSource.mergeE((GValue) literalOrVar); + else if (GValue.valueInstanceOf(literalOrVar, GType.UNKNOWN) && ((GValue) literalOrVar).get() == null) + return this.traversalSource.mergeE((GValue) GValue.ofMap(((GValue) literalOrVar).getName(), null)); else return this.traversalSource.mergeE((Map) literalOrVar); } 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 624e3cfb2e..06a382d179 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 @@ -208,7 +208,6 @@ import org.apache.tinkerpop.gremlin.util.CollectionUtil; import org.apache.tinkerpop.gremlin.util.function.ConstantSupplier; -import java.lang.reflect.Array; import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Arrays; @@ -2888,7 +2887,31 @@ public default GraphTraversal hasId(final Object id, final Object... other // be turned into array first if (otherIds != null) { for (final Object i : otherIds) { - if (id instanceof Object[]) { + // to retain existing behavior, GValue's containing collections are unrolled by 1 layer. + // For example, GValue.of([1, 2]) is processed to [GValue.of(1), GValue.of(2)] + if(i instanceof GValue) { + Object value = ((GValue) i).get(); + if (i instanceof Object[]) { + for (Object o : (Object[]) value) { + if(o instanceof GValue) { + ids.add(o); + } else { + ids.add(GValue.of(null, o)); + } + } + } else if(value instanceof Collection) { + for (Object o : (Collection) value) { + if(o instanceof GValue) { + ids.add(o); + } else { + ids.add(GValue.of(null, o)); + } + } + } else { + ids.add(i); + } + } + else if (i instanceof Object[]) { Collections.addAll(ids, (Object[]) i); } else if (i instanceof Collection) { ids.addAll((Collection) i);