JanusGraph / janusgraph

JanusGraph: an open-source, distributed graph database
https://janusgraph.org
Other
5.28k stars 1.16k forks source link

Support arrays in GraphSON #1295

Open FlorianHockmann opened 5 years ago

FlorianHockmann commented 5 years ago

JanusGraph supports arrays of primitive types for property types:

mgmt.makePropertyKey('vec').dataType(float[]).cardinality(Cardinality.SINGLE).make()

Unfortunately, this feature cannot be used with GraphSON right now as we don't have serialization support for arrays. Instead, the array is serialized as a list by the driver which leads to an error on the server side:

Expected: class [F, found: class java.util.ArrayList

(More information with a concrete example on gremlin-users.)

mad commented 5 years ago

Some related issue with array and bytecode

Sample of code

        Graph graph = TinkerGraph.open();
        GraphTraversalSource traversal = graph.traversal().withRemote(new EmbeddedRemoteConnection(graph.traversal()));

        traversal.addV("A").property("p", new String[] { "A" }).iterate();
        traversal.addV("A").property("p", new String[] { "A", "B", "C" }).iterate();
        System.out.println(traversal.V().valueMap(true).toList());

Result

[{p=[A], id=0, label=A}, {p=[A], id=2, label=A}]

Actual bytecode

[[], [addV(A), property(p, A)]]
[[], [addV(A), property(p, A, B, C)]]

But expected

[[], [addV(A), property(p, [A])]]
[[], [addV(A), property(p, [A, B, C])]]
FlorianHockmann commented 5 years ago

I think this is a general problem in how TinkerPop handles arrays as arguments in Bytecode. It flattens arguments contained in an array which leads to the problem you're describing. If you create a List instead of an array, then it should work.

Can you create an issue with TinkerPop for that? Otherwise, I can also create one.

mad commented 5 years ago

Ok. https://issues.apache.org/jira/browse/TINKERPOP-2186

mickdelaney commented 5 years ago

Is this still something being considered ? It seems the TinkerPop issue is closed: https://issues.apache.org/jira/browse/TINKERPOP-2186

FlorianHockmann commented 5 years ago

The TinkerPop issue was for the problem @mad described where he couldn't get the driver to actually use an array as an argument and not the elements of the array as individual arguments and Stephen provided a workaround for that in the TinkerPop issue. That still leaves us with the question of how we can deserialize arrays in JanusGraph. We might need to add a new GraphSON type for arrays, similar to the existing TinkerPop type for List or we just make sure that lists are deserialized as arrays for JanusGraph (or maybe both).