use a list of maps as input to a query?

18 views
Skip to first unread message

Phil Crosland

unread,
Dec 1, 2021, 3:26:09 PM12/1/21
to Gremlin-users
Hi I currently have code which I would like to update if possible to use a single query. This is a query to detect if an item needs updating using the T.id and a timestamp value. 
Currently the code gets the id/time stamp from the database and compares in code but I'd like to do as a query for all trh erequested objects.

input: [
              {'id': 'id1', 'longTime':  1634757621  }, ....
           ]

query:
g.V('id1').as('a').select('a').by(T.id).as('id').select('a').choose(__.has(' longTime  ',  1634757621  ), constant(false), constant(true)).as('needsUpdate').select('id','needsUpdate')

so what I woudl like is to adapt the query if possible to use the id/timestamps to return id/ifneeds update in one go.
It seems that maybe sack could be used but not having much luck in figuring out how or if it is actually possible

Stephen Mallette

unread,
Dec 2, 2021, 7:08:19 AM12/2/21
to gremli...@googlegroups.com
I think you would structure it like this:

gremlin> m = [1:29,2:27]
==>1=29
==>2=27
gremlin> ids = m.keySet()
==>1
==>2
gremlin> g.withSideEffect('m',m).V(ids).as('v').
......1>   filter(select('m').unfold().as('i').
......2>          where('v',eq('i')).by(id).by(select(keys)).
......3>          where('v',eq('i')).by('age').by(select(values)))
==>v[1]
==>v[2]


I'd restructure to a simple Map of T.id/timestamp and then since you have the T.id, use that directly to V() for the fastest lookup of the initial set of vertices, then iterate those against the "m" index to first match on T.id and then on your timestamp.


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/a075c757-5212-4b1f-bc34-4253d2819ddfn%40googlegroups.com.

Phil Crosland

unread,
Dec 2, 2021, 9:38:07 AM12/2/21
to Gremlin-users
Thanks :) I will try out a few things for that - it's Neptune so some sideeffect stuff doesn't work but will try

Stephen Mallette

unread,
Dec 2, 2021, 9:39:10 AM12/2/21
to gremli...@googlegroups.com
what aspects of withSideEffect() do not work in neptune?

Phil Crosland

unread,
Dec 2, 2021, 9:43:34 AM12/2/21
to Gremlin-users
I am just reading up on it now - there was mention in its gremlin implementation that some side effects were not available, but yes it looks like withSideEffect is ok - thx :)
Reply all
Reply to author
Forward
0 new messages