I am new to graph DB and Gremlin Graph Traversal Language. I have a requirement where a date will be passed by the client running graph query. For a given date , I would need to first find day of the week and query against the property of the vertex / edge. Note: Day of the week will be a property key in my graph Vertex. e.g., Vertex (Retail Store) - Properties of the vertex will reflect whether shop is open or closed. [SUN: CLOSED, MON: OPEN, TUE:OPEN, WED:OPEN, THU:OPEN, FRI:OPEN, SAT: OPEN] . I also understand that there is an alternative way to solve this by requesting client to pass the date and day of the week - I wanted to check feasibility of doing this gremlin as I might have use case to calculate new Date based on the date passed and then find the day of the week. Appreciate thoughts.
0
votes
1 Answers
0
votes
Gremlin as a language doesn't have the capability to natively calculate the day of the week from a date, so you would have to use a lambda to do so within the Gremlin itself (which doesn't always have complete compatibility with all TinkerPop-enabled systems). I think that using a lambda for this purpose would probably lead to some fairly complicated looking Gremlin because you're basically constructing a dynamic property key which will muddy the readability of your code when it can be handled much more simply.
I think you can get to "much more simply" by just pre-calculating the day of the week in your native programming language and then using that value in your Gremlin. In Java, that might look like this (untested):
public String getStoreStatus(Date d, GraphTraversalSource g) {
Calendar cal = Calendar.getInstance();
cal.setTime(d);
String dayOfWeek = cal.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault());
return g.V().has('store','name','Target').values(dayOfWeek).next();
}