janusgraph icon indicating copy to clipboard operation
janusgraph copied to clipboard

Adding support for custom edge ids

Open porunov opened this issue 5 years ago • 7 comments

I think this feature might be useful in some situations. For example when we want to remove the edge and then add it with the same id or if we want to rewrite current edges. I didn't find the reason why we shouldn't allow the users to use custom ids for edges. https://github.com/JanusGraph/janusgraph/blob/d12adfbf083f575fa48860daa37bfbd0e6095369/janusgraph-core/src/main/java/org/janusgraph/graphdb/util/ElementHelper.java#L61

The edge key consists of label + direction + sort key + adjacent vertex id + edge id. I think that we can allow users to use custom id for the last part edge id. There is already property graph.set-vertex-id which allows to set custom vertex ids. We could create graph.set-edge-id which will be an analog for edge id (the last part).

porunov avatar Mar 28 '19 23:03 porunov

Hi @porunov , when do you think this feature will be available?

taabodim avatar Feb 12 '20 11:02 taabodim

Hi @taabodim I don't have plans to work on it soon. So, I don't have any ETA. If you need this feature you may contribute it to JanusGraph. I wil be happy to review the PR for this issue.

porunov avatar Feb 12 '20 14:02 porunov

@porunov I would be more than happy to do it. can you please point me in the right direction with some link to the code and small description of what needs to happen. i will work on it ASAP.

taabodim avatar Feb 12 '20 16:02 taabodim

Hi, I have a assumption.The current edgeid is composed of long_encode(relationId) + long_encode(outV) + long_encode(relationtype.longId()) + long_encode(inV). The relationId is related to the add order(for edge), the relationtype is related to the add order also(for edgelabel). The same edgelabel has the same relationtype. So if we provide the relationId, the edgeid should be customized, and can locate it by this edgeid.

Here is the main modification:

1、 define the ALLOW_SETTING_EDGE_ID in GraphDatabaseConfiguration

2、 define the addEdge func in StandardJanusGraphTx

JanusGraphEdge addEdge(String relationid, JanusGraphVertex outVertex, JanusGraphVertex inVertex, EdgeLabel label)

When the ALLOW_SETTING_EDGE_ID is True, get the edgeid using the former way long_encode(relationId) + long_encode(inV) + long_encode(relationtype.longId()) + long_encode(outV). If this edge is already existed, then return the edge, can update the edge property(or just raise an error); if not, can use the customized relationid as the prefix of the edgeid, a unique one for this edge.
When the ALLOW_SETTING_EDGE_ID is False, just use the old way would be enough.

Another concern is about the tinkerpop, because the addEdge(String relationid, JanusGraphVertex outVertex, JanusGraphVertex inVertex, EdgeLabel label) is not defined in the interface Vertex of tinkerpop, I am not sure whether it is better to modify the tinkerpop also, but this would make the the problem more complex, it is better just focus on the janusgraph. And the addE func is also defined in tinkerpop, may need extra modification in this part.

Is this assumption reasonable? @taabodim @porunov

9lan9 avatar May 04 '20 03:05 9lan9

@9lan9 , @porunov , @taabodim ,

Any updates on this?

@9lan9 ,

Would you mind clarifying the status of your pull request? What has been done and what still needs to be done? Is there a lot more left to be done? What's the acceptance criteria?

Many thanks in advance!

carlspring avatar Sep 22 '20 11:09 carlspring

Hi everyone, is there any update on this?

bragarods avatar Jan 06 '22 22:01 bragarods

Hi @porunov, any updates on this issue or a workaround to provide custom edge ids?

BjarkeTornager avatar Jun 16 '22 08:06 BjarkeTornager