EdgeId and RelationId using VertexWritable

130 views
Skip to first unread message

rafi1...@gmail.com

unread,
Aug 25, 2020, 6:50:44 AM8/25/20
to JanusGraph users
Hi Everyone,

I am using the VertexWritable class of Janusgraph to fetch the data via Spark as below:
-------------------------------------------------------------------------
val rdd0: RDD[(NullWritable, VertexWritable)] = spark.sparkContext.newAPIHadoopRDD(hadoopConfiguration, classOf[CqlInputFormat], classOf[NullWritable], classOf[VertexWritable])

val rdd1: RDD[VertexWritable] = rdd0.map { case (x, y) => y.asInstanceOf[VertexWritable] }
------------------------------------------------------------------

When I use rdd1.map(x => x.edges(Direction.IN)), I get the tinkerpop Edge and the edge.id() returns the relation ID (e[2571][4184-lives->4112]). How do I get the edge Id ==>e[1zf-388-b2t-368][4184-lives->4112]?

HadoopMarc

unread,
Aug 25, 2020, 3:05:54 PM8/25/20
to JanusGraph users
Ok, the form [1zf-388-b2t-368][4184-lives->4112] derives from:

https://github.com/apache/tinkerpop/blob/3.4.7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/StringFactory.java

return E + L_BRACKET + edge.id() + R_BRACKET + L_BRACKET + edge.outVertex().id() + DASH + edge.label() + ARROW + edge.inVertex().id() + R_BRACKET;

You can also check in the console:

gremlin> import org.janusgraph.util.encoding.LongEncoding
gremlin> LongEncoding.encode(2571L)
==>1zf
gremlin> LongEncoding.encode(4184L)
==>388
gremlin> LongEncoding.encode(4112L)
==>368

I guess you have to typecast the edge.id() result to the JanusGraph RelationIdentifier somehow to get the canonical form you want. My scala is a bit rusty, so I leave that to you.

Btw, it can hardly be a coincidence that someone else had the same problem in a current thread!

Marc

Op dinsdag 25 augustus 2020 om 12:50:44 UTC+2 schreef rafi1...@gmail.com:

rafi1...@gmail.com

unread,
Aug 26, 2020, 3:05:32 AM8/26/20
to JanusGraph users
Thanks Marc

I understood the encoding part of the edge_id components. I have few more doubts.
If we look at the example [1zf-388-b2t-368][4184-lives->4112] 
1zf = LongEncoding.encode(2571L) ... RelationId
388 = LongEncoding.encode(4184L) ... Outgoing vertex ID
368 =  LongEncoding.encode(4112L) Incoming vertex ID
b2t = ? ( unknown) ...  From the Relation Identifier , i saw the fourth part is the typeID but what is this and how is it being derived is still unclear to me.

Since I dont have the type ID with me , it seems that the typecasting to RelationIdentifier would not be possible.

Thanks

Rafi

HadoopMarc

unread,
Aug 26, 2020, 5:02:50 AM8/26/20
to JanusGraph users
Hi Rafi,

Ok, let's go one step deeper. The StringFactory comes from TinkerPop and does not know about JanusGraph Relationidentifier. The same holds for HadoopGraph. So the HadoopGraph object uses the Edge interface as generic object type for edges. For edge.id() to return the format you expect from a JanuGraphEdge, the RelationIdentifier.toString() method needs to be called. You can only achieve this by explicitly casting the edge.id() object to a RelationIdentifier (or maybe by casting edge to a JanusGraphEdge).

HTH,    Marc

Op woensdag 26 augustus 2020 om 09:05:32 UTC+2 schreef rafi1...@gmail.com:

rafi1...@gmail.com

unread,
Sep 1, 2020, 7:30:22 AM9/1/20
to JanusGraph users
Hi Marc,

I tried to cast the tinkerpop edge to JanusGraph edge but no luck. Is there any way by which I can derive the typeId part of the edgeId myself?

anjani...@gmail.com

unread,
Oct 14, 2020, 7:18:00 AM10/14/20
to JanusGraph users
Hi Rafi,

I am also having same need and was exploring on it. Found that typeId is derived from edgeLabel. EdgeLabel is converted to number using some encloding logic. Though i am not able to figure  exact logic for same but noticed that typeId is always same for same EdgeLabel. Say we have multiple edge with same Label then for all of those edges typeId will be same, rest other 3 param will differ.

Let me know if you were able to figure out more on it.

Thanks,
Anjani

rafi1...@gmail.com

unread,
Oct 16, 2020, 3:03:27 AM10/16/20
to JanusGraph users
Hi Anjani

Even I noticed the same (typeId is derived from edgeLabel) but the exact logic is still unknown to me too. For now I am relying on the observation that the typeId remains same for same edgeLabel type and use that for hard-coding the typeId part.

HTH

Regards

Rafi

anjani...@gmail.com

unread,
Oct 27, 2020, 5:12:23 AM10/27/20
to JanusGraph users
Yes Rafi, even i am doing same for now. 

Thanks,
Anjani

Reply all
Reply to author
Forward
0 new messages