This is an automated email from the ASF dual-hosted git repository.

xiazcy pushed a commit to branch gvalue-feature-tests
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/gvalue-feature-tests by this 
push:
     new e05fcaaf87 added GValue, restored Merge serializers, and updated tests 
in Python, removed Parameter class, restored GraphSON Merge serializer in Java
e05fcaaf87 is described below

commit e05fcaaf8764adc098d9c33e6f6f238f70f8b079
Author: Yang Xia <[email protected]>
AuthorDate: Mon Nov 25 10:08:47 2024 -0800

    added GValue, restored Merge serializers, and updated tests in Python, 
removed Parameter class, restored GraphSON Merge serializer in Java
---
 .../gremlin/process/traversal/GremlinLang.java     | 26 ------------------
 .../structure/io/graphson/GraphSONModule.java      |  2 ++
 .../gremlin/process/traversal/GremlinLangTest.java |  3 +-
 .../dsl/graph/GraphTraversalSourceTest.java        |  1 -
 gremlin-python/docker-compose.yml                  |  2 ++
 .../python/gremlin_python/process/traversal.py     | 32 ++++++++++++----------
 .../gremlin_python/structure/io/graphbinaryV4.py   |  8 +++++-
 .../gremlin_python/structure/io/graphsonV4.py      |  9 ++++++
 .../src/main/python/radish/feature_steps.py        | 12 ++++++--
 .../src/main/python/tests/driver/test_client.py    |  4 +--
 .../tests/driver/test_driver_remote_connection.py  |  4 +--
 .../main/python/tests/process/test_gremlin_lang.py | 28 +++++++++----------
 12 files changed, 67 insertions(+), 64 deletions(-)

diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GremlinLang.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GremlinLang.java
index cd973f56f0..c0829607ca 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GremlinLang.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GremlinLang.java
@@ -170,7 +170,6 @@ public class GremlinLang implements Cloneable, Serializable 
{
             return gremlinLang.getGremlin("__");
         }
 
-        // TODO old Parameters tests will fail, reminder to check them
         if (arg instanceof GValue) {
             final GValue gValue = (GValue) arg;
             String key = gValue.getName();
@@ -473,31 +472,6 @@ public class GremlinLang implements Cloneable, 
Serializable {
         }
     }
 
-    /**
-     * Parameter to be used in Traversal.
-     */
-    public static class Parameter {
-        private final String key;
-        private final Object value;
-
-        private Parameter(final String key, final Object value) {
-            this.key = key;
-            this.value = value;
-        }
-
-        public static Parameter var(final String key, final Object value) {
-            if (key != null && key.startsWith("_")) {
-                throw new IllegalArgumentException(String.format("Invalid 
parameter name [%s]. Should not start with _.", key));
-            }
-
-            return new Parameter(key, value);
-        }
-
-        public static Parameter value(final Object value) {
-            return new Parameter(null, value);
-        }
-    }
-
     /////
 
     private Object[] flattenArguments(final Object... arguments) {
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
index c18f3b05c5..cb60a0af8a 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
@@ -166,6 +166,7 @@ abstract class GraphSONModule extends 
TinkerPopJacksonModule {
                     put(Tree.class, "Tree");
                     Stream.of(
                             Direction.class,
+                            Merge.class,
                             T.class).forEach(e -> put(e, e.getSimpleName()));
                 }});
 
@@ -202,6 +203,7 @@ abstract class GraphSONModule extends 
TinkerPopJacksonModule {
             addSerializer(BulkSet.class, new 
TraversalSerializersV4.BulkSetJacksonSerializer());
             Stream.of(
                     Direction.class,
+                    Merge.class,
                     T.class).forEach(e -> addSerializer(e, new 
TraversalSerializersV4.EnumJacksonSerializer()));
 
             /////////////////////// DESERIALIZERS ////////////////////////////
diff --git 
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/GremlinLangTest.java
 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/GremlinLangTest.java
index d21beed912..d8575e562b 100644
--- 
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/GremlinLangTest.java
+++ 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/GremlinLangTest.java
@@ -18,7 +18,6 @@
  */
 package org.apache.tinkerpop.gremlin.process.traversal;
 
-import org.apache.tinkerpop.gremlin.process.traversal.GremlinLang.Parameter;
 import 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 import org.apache.tinkerpop.gremlin.process.traversal.step.GValue;
@@ -122,7 +121,7 @@ public class GremlinLangTest {
                 
{g.withStrategies(SubgraphStrategy.build().vertices(__.has("name", 
P.within("josh", "lop", "ripple"))).create()).V(),
                         "g.withStrategies(new 
SubgraphStrategy(checkAdjacentVertices:true,vertices:__.has(\"name\",P.within([\"josh\",\"lop\",\"ripple\"])))).V()"},
                 {g.inject(GValue.of("x", "x")).V(GValue.of("ids", new int[]{1, 
2, 3})), "g.inject(x).V(ids)"},
-                {newG().inject(Parameter.value("test1"), 
Parameter.value("test2")), "g.inject(_0,_1)"},
+                {newG().inject(GValue.of("test1"), GValue.of("test2")), 
"g.inject(_0,_1)"},
                 {newG().inject(new HashSet<>(Arrays.asList(1, 2))), 
"g.inject({1,2})"},
         });
     }
diff --git 
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSourceTest.java
 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSourceTest.java
index 83bc03ad44..3fcbcf446a 100644
--- 
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSourceTest.java
+++ 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSourceTest.java
@@ -41,7 +41,6 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import static 
org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
-import static 
org.apache.tinkerpop.gremlin.process.traversal.GremlinLang.Parameter.value;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static 
org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
 import static org.hamcrest.core.Is.is;
diff --git a/gremlin-python/docker-compose.yml 
b/gremlin-python/docker-compose.yml
index b912c907cc..85cec1d59d 100644
--- a/gremlin-python/docker-compose.yml
+++ b/gremlin-python/docker-compose.yml
@@ -64,7 +64,9 @@ services:
       && python3 ./setup.py test
       && python3 ./setup.py install
       && radish -f dots -e -t -b ./radish ./gremlin-test 
--user-data='serializer=application/vnd.graphbinary-v4.0' 
--user-data='bulked=true'
+      && radish -f dots -e -t -b ./radish ./gremlin-test 
--user-data='serializer=application/vnd.graphbinary-v4.0' 
--user-data='parameterize=true'
       && radish -f dots -e -t -b ./radish ./gremlin-test 
--user-data='serializer=application/vnd.graphbinary-v4.0'
+      && radish -f dots -e -t -b ./radish ./gremlin-test 
--user-data='serializer=application/vnd.gremlin-v4.0+json' 
--user-data='parameterize=true'
       && radish -f dots -e -t -b ./radish ./gremlin-test 
--user-data='serializer=application/vnd.gremlin-v4.0+json';
       EXIT_CODE=$$?; chown -R `stat -c "%u:%g" .` .; exit $$EXIT_CODE"
     depends_on:
diff --git a/gremlin-python/src/main/python/gremlin_python/process/traversal.py 
b/gremlin-python/src/main/python/gremlin_python/process/traversal.py
index bed20abc0b..6032b8bda8 100644
--- a/gremlin-python/src/main/python/gremlin_python/process/traversal.py
+++ b/gremlin-python/src/main/python/gremlin_python/process/traversal.py
@@ -23,7 +23,7 @@ import threading
 import warnings
 
 from aenum import Enum
-from gremlin_python.structure.graph import Vertex
+from gremlin_python.structure.graph import Vertex, Edge, Path, Property
 
 from .. import statics
 from ..statics import long, SingleByte, short, bigint, BigDecimal
@@ -853,8 +853,8 @@ class GremlinLang(object):
             self.parameters.update(gremlin_lang.parameters)
             return gremlin_lang.get_gremlin('__')
 
-        if isinstance(arg, Parameter):
-            key = arg.key
+        if isinstance(arg, GValue):
+            key = arg.get_name()
             if key is None:
                 key = f'_{self.param_count.get_and_increment()}'
 
@@ -1085,20 +1085,24 @@ class GremlinLang(object):
     #         return Bytecode._create_graph_op("tx", "rollback")
 
 
-class Parameter:
-    def __init__(self, key, value):
-        self.key = key
+class GValue:
+    def __init__(self, name=None, value=None):
+        if name is not None and name.startswith('_'):
+            raise Exception(f'invalid GValue name {name}. Should not start 
with _.')
+        self.name = name
         self.value = value
 
-    @staticmethod
-    def var(key, value):
-        if key is not None and key.startswith('_'):
-            raise Exception(f'invalid parameter name {key}. Should not start 
with _.')
-        return Parameter(key, value)
+    def is_variable(self):
+        return self.name is not None
 
-    @staticmethod
-    def value(value):
-        return Parameter(None, value)
+    def get_name(self):
+        return self.name
+
+    def is_null(self):
+        return self.value is None
+
+    def get(self):
+        return self.value
 
 
 class CardinalityValue(GremlinLang):
diff --git 
a/gremlin-python/src/main/python/gremlin_python/structure/io/graphbinaryV4.py 
b/gremlin-python/src/main/python/gremlin_python/structure/io/graphbinaryV4.py
index 7f646b0cbb..7e7eeb81bd 100644
--- 
a/gremlin-python/src/main/python/gremlin_python/structure/io/graphbinaryV4.py
+++ 
b/gremlin-python/src/main/python/gremlin_python/structure/io/graphbinaryV4.py
@@ -27,7 +27,7 @@ from datetime import datetime, timedelta, timezone
 from struct import pack, unpack
 
 from aenum import Enum
-from gremlin_python.process.traversal import Direction, T
+from gremlin_python.process.traversal import Direction, T, Merge
 from gremlin_python.statics import FloatType, BigDecimal, ShortType, IntType, 
LongType, BigIntType, \
     DictType, SetType, SingleByte, SingleChar
 from gremlin_python.structure.graph import Graph, Edge, Property, Vertex, 
VertexProperty, Path
@@ -62,6 +62,7 @@ class DataType(Enum):
     vertexproperty = 0x12
     direction = 0x18
     t = 0x20
+    merge = 0x2e
     bigdecimal = 0x22
     biginteger = 0x23
     byte = 0x24
@@ -740,6 +741,11 @@ class TIO(_EnumIO):
     python_type = T
 
 
+class MergeIO(_EnumIO):
+    graphbinary_type = DataType.merge
+    python_type = Merge
+
+
 class ByteIO(_GraphBinaryTypeIO):
     python_type = SingleByte
     graphbinary_type = DataType.byte
diff --git 
a/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV4.py 
b/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV4.py
index 87183d420f..438c5d44f1 100644
--- a/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV4.py
+++ b/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV4.py
@@ -577,3 +577,12 @@ class DirectionIO(_GraphSONTypeIO):
     @classmethod
     def objectify(cls, d, reader):
         return Direction[d]
+
+
+class EnumSerializer(_GraphSONTypeIO):
+    python_type = Enum
+
+    @classmethod
+    def dictify(cls, enum, _):
+        return 
GraphSONUtil.typed_value(SymbolUtil.to_camel_case(type(enum).__name__),
+                                        
SymbolUtil.to_camel_case(str(enum.name)))
diff --git a/gremlin-python/src/main/python/radish/feature_steps.py 
b/gremlin-python/src/main/python/radish/feature_steps.py
index 5f72c5b0dc..88f9dcbaf7 100644
--- a/gremlin-python/src/main/python/radish/feature_steps.py
+++ b/gremlin-python/src/main/python/radish/feature_steps.py
@@ -25,7 +25,7 @@ from gremlin_python.structure.graph import Path, Vertex
 from gremlin_python.process.anonymous_traversal import traversal
 from gremlin_python.process.graph_traversal import __
 from gremlin_python.process.traversal import Barrier, Cardinality, P, TextP, 
Pop, Scope, Column, Order, Direction, T, \
-    Pick, Operator, IO, WithOptions, Merge
+    Pick, Operator, IO, WithOptions, Merge, GValue
 from radish import given, when, then, world
 from hamcrest import *
 
@@ -127,7 +127,15 @@ def translate_traversal(step):
     if step.context.ignore:
         return
 
-    p = step.context.traversal_params if hasattr(step.context, 
"traversal_params") else {}
+    p = {}
+    if hasattr(step.context, "traversal_params"):
+        # user flag "parameterize", when set to 'true' will use GValue to 
parameterize parameters instead of flattening them out into string
+        if world.config.user_data.get("parameterize"):
+            for k, v in step.context.traversal_params.items():
+                p[k] = GValue(k, v)
+        else:
+            p = step.context.traversal_params
+
     localg = step.context.g
 
     tagset = [tag.name for tag in step.all_tags]
diff --git a/gremlin-python/src/main/python/tests/driver/test_client.py 
b/gremlin-python/src/main/python/tests/driver/test_client.py
index 4b6a9ad11b..90023b9e76 100644
--- a/gremlin-python/src/main/python/tests/driver/test_client.py
+++ b/gremlin-python/src/main/python/tests/driver/test_client.py
@@ -28,7 +28,7 @@ from gremlin_python.driver.protocol import GremlinServerError
 from gremlin_python.driver.request import RequestMessage
 from gremlin_python.driver.serializer import GraphBinarySerializersV4
 from gremlin_python.process.graph_traversal import __, GraphTraversalSource
-from gremlin_python.process.traversal import TraversalStrategies, Parameter
+from gremlin_python.process.traversal import TraversalStrategies, GValue
 from gremlin_python.process.strategies import OptionsStrategy
 from gremlin_python.structure.graph import Graph, Vertex
 from gremlin_python.driver.aiohttp.transport import AiohttpHTTPTransport
@@ -265,7 +265,7 @@ def test_client_gremlin_lang_options(client):
 def test_client_gremlin_lang_request_options_with_binding(client):
     g = GraphTraversalSource(Graph(), TraversalStrategies())
     # Note that bindings for constructed traversals is done via Parameter only
-    t = g.with_('language', 'gremlin-lang').V(Parameter.var('x', [1, 2, 
3])).count()
+    t = g.with_('language', 'gremlin-lang').V(GValue('x', [1, 2, 3])).count()
     request_opts = 
DriverRemoteConnection.extract_request_options(t.gremlin_lang)
     message = create_basic_request_message(t)
     result_set = client.submit(message, request_options=request_opts)
diff --git 
a/gremlin-python/src/main/python/tests/driver/test_driver_remote_connection.py 
b/gremlin-python/src/main/python/tests/driver/test_driver_remote_connection.py
index 86d6445316..8f2f3321cf 100644
--- 
a/gremlin-python/src/main/python/tests/driver/test_driver_remote_connection.py
+++ 
b/gremlin-python/src/main/python/tests/driver/test_driver_remote_connection.py
@@ -21,7 +21,7 @@ import os
 from gremlin_python import statics
 from gremlin_python.driver.driver_remote_connection import 
DriverRemoteConnection
 from gremlin_python.statics import long
-from gremlin_python.process.traversal import TraversalStrategy, P, Order, T, 
DT, Parameter, Cardinality
+from gremlin_python.process.traversal import TraversalStrategy, P, Order, T, 
DT, GValue, Cardinality
 from gremlin_python.process.graph_traversal import __
 from gremlin_python.process.anonymous_traversal import traversal
 from gremlin_python.structure.graph import Vertex
@@ -115,7 +115,7 @@ class TestDriverRemoteConnection(object):
         g = traversal().with_(remote_connection)
         t = g.with_("evaluationTimeout",
                     1000).with_("batchSize", 100).with_("userAgent",
-                                                        
"test").V(Parameter.var('ids', [1, 2, 3])).count()
+                                                        
"test").V(GValue('ids', [1, 2, 3])).count()
         assert remote_connection.extract_request_options(t.gremlin_lang) == 
{'batchSize': 100,
                                                                              
'evaluationTimeout': 1000,
                                                                              
'userAgent': 'test',
diff --git a/gremlin-python/src/main/python/tests/process/test_gremlin_lang.py 
b/gremlin-python/src/main/python/tests/process/test_gremlin_lang.py
index 0ff3ce69b5..d4046759cf 100644
--- a/gremlin-python/src/main/python/tests/process/test_gremlin_lang.py
+++ b/gremlin-python/src/main/python/tests/process/test_gremlin_lang.py
@@ -21,7 +21,7 @@ Unit tests for the GremlinLang Class. Modified from 
deprecated Groovy Translator
 """
 from gremlin_python.process.strategies import ReadOnlyStrategy, 
SubgraphStrategy, OptionsStrategy, PartitionStrategy
 from gremlin_python.process.traversal import within, eq, T, Order, Scope, 
Column, Operator, P, Pop, Cardinality, \
-    between, inside, WithOptions, ShortestPath, starting_with, ending_with, 
containing, gt, lte, Parameter
+    between, inside, WithOptions, ShortestPath, starting_with, ending_with, 
containing, gt, lte, GValue
 from gremlin_python.statics import SingleByte, short, long, bigint, BigDecimal
 from gremlin_python.structure.graph import Graph, Vertex, Edge, VertexProperty
 from gremlin_python.process.anonymous_traversal import traversal
@@ -473,45 +473,45 @@ class TestGremlinLang(object):
             gremlin_lang = tests[t][0].gremlin_lang.get_gremlin()
             assert gremlin_lang == tests[t][1]
 
-    def test_parameters_name_dont_need_escaping(self):
+    def test_gvalue_name_dont_need_escaping(self):
         g = traversal().with_(None)
         try:
-            g.V(Parameter.var('\"', [1, 2, 3]))
+            g.V(GValue('\"', [1, 2, 3]))
         except Exception as ex:
             assert str(ex) == 'invalid parameter name ".'
 
-    def test_parameters_is_not_number(self):
+    def test_gvalue_is_not_number(self):
         g = traversal().with_(None)
         try:
-            g.V(Parameter.var('1', [1, 2, 3]))
+            g.V(GValue('1', [1, 2, 3]))
         except Exception as ex:
             assert str(ex) == 'invalid parameter name 1.'
 
-    def test_parameters_is_valid_identifier(self):
+    def test_gvalue_is_valid_identifier(self):
         g = traversal().with_(None)
         try:
-            g.V(Parameter.var('1a', [1, 2, 3]))
+            g.V(GValue('1a', [1, 2, 3]))
         except Exception as ex:
             assert str(ex) == 'invalid parameter name 1a.'
 
-    def test_parameters_is_not_reserved(self):
+    def test_gvalue_is_not_reserved(self):
         g = traversal().with_(None)
         try:
-            g.V(Parameter.var('_1', [1, 2, 3]))
+            g.V(GValue('_1', [1, 2, 3]))
         except Exception as ex:
-            assert str(ex) == 'invalid parameter name _1. Should not start 
with _.'
+            assert str(ex) == 'invalid GValue name _1. Should not start with 
_.'
 
-    def test_parameters_is_not_duplicate(self):
+    def test_gvalue_is_not_duplicate(self):
         g = traversal().with_(None)
         try:
-            g.inject(Parameter.var('ids', [1, 2])).V(Parameter.var('ids', [2, 
3]))
+            g.inject(GValue('ids', [1, 2])).V(GValue('ids', [2, 3]))
         except Exception as ex:
             assert str(ex) == 'parameter with name ids already exists.'
 
-    def test_parameters_allow_parameter_reuse(self):
+    def test_gvalue_allow_parameter_reuse(self):
         g = traversal().with_(None)
         val = [1, 2, 3]
-        p = Parameter.var('ids', val)
+        p = GValue('ids', val)
         gremlin = g.inject(p).V(p).gremlin_lang
         assert 'g.inject(ids).V(ids)' == gremlin.get_gremlin()
         assert val == gremlin.get_parameters().get('ids')

Reply via email to