addE and property in bulk without using sideEffect

31 views
Skip to first unread message

Hoyeung Chan

unread,
Jan 19, 2023, 5:47:33 AM1/19/23
to Gremlin-users
Hi, everyone. I am trying to upsert edges in bulk with maps. My code works in most cases and fails if the edges I am dealing with allow multiple connections and throw a " sort key" Exception. Can I execute addE() with property() in bulk without using sideEffect()? 

Here is  my code:
g.inject(relationList)
.unfold()
.as("relationList")
.select("label")
.as("label")
.select("relationList")
.V()
.where(P.eq("relationList"))
.by(T.id)
.by(__.select("from").as("from"))
.coalesce(__.inE()
.where(P.eq("label"))
.by(T.label)
.by()
.filter(__.outV().where(P.eq("relationList")).by(T.id).by(__.select("to"))), __.addE(__.select("label"))
.from(__.V().where(P.eq("relationList")).by(T.id).by(__.select("from")))
.to(__.V().where(P.eq("relationList")).by(T.id).by(__.select("to"))))
.as("edge")
.sideEffect(__.select("relationList")
.select("properties")
.unfold()
.as("keyValue")
.select("edge")
.property(__.select("keyValue").by(Column.keys), __.select("keyValue").by(Column.values)))

It works for edges allowing only a single connection. 

My Hypothesis is that the properties of these edges are nullable so that we can set them later using sideEffect() and property(). For multiple-connection edges properties(sort keys) should always come along with addE(). With sideEffect() it won't work.
like this,
g.addE("label").property("sortKey1","value1").property("sortKey2","value2")

Things that I tried:
I have tried putting property() right after the addE(), by doing this, I set only one property for each edge in single-connection cases and failed in multiple-connection cases.


Other Information: 
I am using HugeGraph, which is compatible with the Gremlin query language. There are two types of edges in HugeGraph, 
single connection: The user can only connect two vertices with the same labelled edge once
multi connection: The user can connect two vertices multiple times if the sort keys are set.


Reply all
Reply to author
Forward
0 new messages