Is there a way to run closures locally in my gremlin console?

81 views
Skip to first unread message

Daniel Craig

unread,
Aug 12, 2022, 2:27:17 PM8/12/22
to Gremlin-users
Is there a way to run closures locally in my gremlin console?  It appears that Neptune doesn't allow them and I want to use one to turn a date (YYYYMMDD) into a millis datetime.

Here is the java code that I want to do:

```
LocalDate.parse("20220812", DateTimeFormatter.BASIC_ISO_DATE).atStartOfDay(ZoneId.of("America/Chicago")).toInstant().toEpochMilli()
```

Kelvin Lawrence

unread,
Aug 15, 2022, 1:34:30 PM8/15/22
to Gremlin-users
Using a local Gremlin Console, attached to a graph such as TinkerGraph, you can write the query along these lines:

gremlin> g.inject(0).map {LocalDate.parse("20220812", DateTimeFormatter.BASIC_ISO_DATE).atStartOfDay(ZoneId.of("America/Chicago")).toIn
stant().toEpochMilli()}
==>1660280400000 
 

Kelvin Lawrence

unread,
Aug 15, 2022, 1:35:22 PM8/15/22
to Gremlin-users
You will need to import those classes into the Console, such as

gremlin> import java.time.ZoneId  

Daniel Craig

unread,
Aug 15, 2022, 2:26:18 PM8/15/22
to Gremlin-users
Is there a way to do it while connected to Neptune?  I want to use the timestamp as part of a "has()" traversal step in a query.

I get the following issue when I attempt your example while connected to Neptune

gremlin> g.inject(0).map {LocalDate.parse("20220812", DateTimeFormatter.BASIC_ISO_DATE).atStartOfDay(ZoneId.of("America/Chicago")).toInstant().toEpochMilli()}
{"requestId":"6e7b3cae-633c-4eea-94e2-3ec0fe6a11d4","code":"MalformedQueryException","detailedMessage":"Failed to interpret Gremlin query: Query parsing failed at line 1, character position at 17, error message : token recognition error at: 'L'"}
Type ':help' or ':h' for help.
Display stack trace? [yN]
gremlin>

Kelvin Lawrence

unread,
Aug 15, 2022, 2:34:25 PM8/15/22
to Gremlin-users
Neptune cannot itself accept a closure/lambda, however if all you need to do is calculate it locally and then issue a query, you can set the Gremlin console up in a way that allows you to use local variables. The steps are discussed at [1] - I will also try to work up an actual example.

Kelvin Lawrence

unread,
Aug 15, 2022, 2:45:04 PM8/15/22
to Gremlin-users
Assuming you are connected using the "An alternate way to connect" method, you can do - 

gremlin> t=LocalDate.parse("20220812", DateTimeFormatter.BASIC_ISO_DATE).atStartOfDay(ZoneId.of("America/Chicago")).toInstant().toEpochMilli();[]

gremlin> g.addV('x').property('timestamp',t)
==>v[02c15168-c89e-8a28-7fe5-42e7a9242046]

gremlin> g.V('02c15168-c89e-8a28-7fe5-42e7a9242046').valueMap()
==>[timestamp:[1660280400000]]


Daniel Craig

unread,
Aug 15, 2022, 3:23:28 PM8/15/22
to gremli...@googlegroups.com
Thanks this is a huge help to me! 

--
You received this message because you are subscribed to a topic in the Google Groups "Gremlin-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gremlin-users/CY0ZCOyWOTE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/145b2c0f-c158-4106-8f6f-58318b2c42d6n%40googlegroups.com.

Philip Crosland

unread,
Nov 29, 2022, 11:50:41 AM11/29/22
to Gremlin-users
from this it looks like it woudl be possible to extract a sub-graph into local gremlin console from neptune and work on that locally - is that correct? I can no longer use Neptune as work is laying me off at end of year and I dont have a personal account set up with data
Reply all
Reply to author
Forward
0 new messages