In JanusGraph, I want to get min() of some Date
properties.
Since both min() and max() supports only Number
type, I use map{it.get().getTime()}
. But strange result.
How to do it ?
- JanusGraph version: github master (build at about 2 weeks ago)
- Gremlin version: 3.2.6
Schema definition
gremlin> mgmt = graph.openManagement()
==>org.janusgraph.graphdb.database.management.ManagementSystem@496a8a94
gremlin> person = mgmt.makeVertexLabel('Person').make()
==>Person
gremlin> t_created = mgmt.makePropertyKey('t_created').dataType(Date.class).cardinality(SINGLE).make()
==>t_created
gremlin> t_modified = mgmt.makePropertyKey('t_modified').dataType(Date.class).cardinality(SINGLE).make()
==>t_modified
gremlin> mgmt.buildIndex('i_t_created', Vertex.class).addKey(t_created).buildMixedIndex('search')
==>i_t_created
gremlin> mgmt.buildIndex('i_t_modified', Vertex.class).addKey(t_modified).buildMixedIndex('search')
==>i_t_modified
gremlin> mgmt.commit()
==>null
My gremlin console code
gremlin> person = g.addV('Person').property('t_created', new Date()).property('t_modified', new Date()).next()
==>v[16488]
gremlin> g.tx().commit()
==>null
gremlin> g.V(person).properties()
==>vp[t_created->Tue Sep 05 07:40:16 ]
==>vp[t_modified->Tue Sep 05 07:40:16 ]
gremlin> g.V(person).values('t_created', 't_modified')
==>Tue Sep 05 07:40:16 UTC 2017
==>Tue Sep 05 07:40:16 UTC 2017
gremlin> g.V(person).values('t_created', 't_modified').min()
java.util.Date cannot be cast to java.lang.Number
Type ':help' or ':h' for help.
Display stack trace? [yN]
gremlin> g.V(person).values('t_created', 't_modified').map{it.get().getTime()}
==>1504597216099
==>1504597216099
// max() is OK
gremlin> g.V(person).values('t_created', 't_modified').map{it.get().getTime()}.max()
==>1504597216099
// Why min() is 2147483647 ?
gremlin> g.V(person).values('t_created', 't_modified').map{it.get().getTime()}.min()
==>2147483647
I don't know why you get 2147483647, but here's something else you can try:
The good thing about this approach is, that it doesn't need a lambda step.