Converting long value(epoch) to Date format using gremlin query

半城伤御伤魂 提交于 2019-12-11 17:43:35

问题


I have vertex created date in long format (epoch). I want to convert the long value into particular date format (YYYY-MM or YYYY-MM-DD) using gremlin query. .map or .transform is not working. Can someone please help.


回答1:


The Gremlin language doesn't have built in features to convert dates. You would have to use a lambda if you want to do it within Gremlin - for Groovy it would look like:

gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV('person').property('dob',Date.parse('yyyy-MM-dd','2018-10-01').getTime())
==>v[0]
gremlin> g.V().valueMap()
==>[dob:[1538366400000]]
gremlin> g.V().values('dob').map{new Date(it.get()).format('yyyy-MM-dd')}
==>2018-10-01

You could write the same in Java by skipping the shorthand Groovy provides and just using SimpleDateTime in the lambda. Of course, TinkerPop advises against lambdas and in this case, I think that the better solution is to simply return your result as a Long and then transform it on the client as needed once in hand.



来源:https://stackoverflow.com/questions/52963012/converting-long-valueepoch-to-date-format-using-gremlin-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!