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 2020/08/25 11:50:03 UTC
[tinkerpop] 01/02: Added support for dict as keys,
as required by the following example statement:
g.V().as_('a').out().as_('b').out().as_('c').dedup('a', 'b',
'c').groupCount().by(select('a', 'b').by(valueMap(True))).toList()
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2407
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 99a9bee665cf45f6b5079680c7cc28c563ebb4f9
Author: Liran Moysi <li...@gmail.com>
AuthorDate: Wed Jul 22 15:13:25 2020 +0300
Added support for dict as keys, as required by the following example statement: g.V().as_('a').out().as_('b').out().as_('c').dedup('a','b','c').groupCount().by(select('a', 'b').by(valueMap(True))).toList()
---
.../gremlin_python/structure/io/graphsonV3d0.py | 23 +++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV3d0.py b/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV3d0.py
index 21c31ba..4d5a288 100644
--- a/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV3d0.py
+++ b/gremlin-python/src/main/python/gremlin_python/structure/io/graphsonV3d0.py
@@ -42,6 +42,27 @@ _serializers = OrderedDict()
_deserializers = {}
+class hashable_dict(dict):
+ def __hash__(self):
+ try:
+ return hash(tuple(sorted(self.items())))
+ except:
+ return hash(tuple(sorted(str(x) for x in self.items())))
+
+ @classmethod
+ def of(cls, o):
+ if isinstance(o, (tuple, set, list)):
+ return tuple([cls.of(e) for e in o])
+ elif not isinstance(o, (dict, hashable_dict)):
+ return o
+
+ new_o = hashable_dict()
+ for k, v in o.items():
+ new_o[k] = cls.of(v)
+ return new_o
+
+
+
class GraphSONTypeType(type):
def __new__(mcs, name, bases, dct):
cls = super(GraphSONTypeType, mcs).__new__(mcs, name, bases, dct)
@@ -476,7 +497,7 @@ class MapType(_GraphSONTypeIO):
if len(l) > 0:
x = 0
while x < len(l):
- new_dict[reader.toObject(l[x])] = reader.toObject(l[x + 1])
+ new_dict[hashable_dict.of(reader.toObject(l[x]))] = reader.toObject(l[x + 1])
x = x + 2
return new_dict