在 JanusGraph 中,我想获取一些Date
属性的 min() 。
由于 min() 和 max() 都只支持Number
类型,所以我使用map{it.get().getTime()}
. 但奇怪的结果。
怎么做 ?
- JanusGraph 版本:github master(大约 2 周前构建)
- 小鬼版本:3.2.6
架构定义
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