在JanusGraph中,我想获得一些Date
属性的min()。
由于min()和max()仅支持Number
类型,因此我使用map{it.get().getTime()}
。但奇怪的结果。
怎么做?
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
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
答案 0 :(得分:6)
我不知道你为什么会得到2147483647,但是你可以尝试其他的东西:
gremlin> g.addV().property("foo", new Date())
==>v[0]
gremlin> g.addV().property("foo", new Date())
==>v[2]
gremlin> g.V().values("foo")
==>Tue Sep 05 07:02:15 MST 2017
==>Tue Sep 05 07:02:18 MST 2017
gremlin> g.V().values("foo").order().by().limit(1) // min()
==>Tue Sep 05 07:02:15 MST 2017
gremlin> g.V().values("foo").order().by(decr).limit(1) // max()
==>Tue Sep 05 07:02:18 MST 2017
这种方法的好处是,它不需要lambda步骤。