【发布时间】:2020-03-16 07:45:41
【问题描述】:
有没有办法在 Gremlin 遍历中做类似的事情? 我本以为这很明显,但似乎我错了。 我有一个包含两个日期(都是时间戳)的表,我想只选择一个大于另一个的记录。比如:
has('date_one', P.gt('date_two'))
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: timestamp with time zone > character varying
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
那么第二个参数不会被翻译成列'date_two'的值。
基于答案 1,完整的请求变为:
g.V().hasLabel('File').where(or (
__.out('has_Ref1').hasNot('date_one'),
__.out('has_Ref1').as('s1', 's2').where('s1', gt('s2')).by('date_two').by('date_one')))
.as('file').out('has_Ref1').as('ref1').out('has_Content').as('data').select('file','ref1','data')
But in this case: A where()-traversal must have at least a start or end label (i.e. variable): [OrStep([[VertexStep(OUT,[has_Ref1],vertex), NotStep([PropertiesStep([date_one],value)])], [VertexStep(OUT,[has_Ref1],vertex)@[s1, s2], WherePredicateStep(s1,gt(s2),[value(date_two), value(date_one)])]])]
我猜 or 子句的第二个参数必须是布尔值。然后,如果我尝试添加 '.hasNext()',则会出现以下异常:
g.V().hasLabel('File').where(or (
__.out('has_Ref1').hasNot('date_one'),
__.out('has_Ref1').as('s1', 's2').where('s1', gt('s2')).by('date_two').by('date_one').hasNext()))
.as('file').out('has_Ref1').as('ref1').out('has_Content').as('data').select('file','ref1','data')
groovy.lang.MissingMethodException: No signature of method: static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.or() is applicable for argument types: (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal...) values: [[VertexStep(OUT,[has_Ref1],vertex), NotStep([PropertiesStep([date_one],value)])], ...]
【问题讨论】:
-
该错误表明您的“真实”查询与您所写的查询不同。我怀疑
asg.modifiedAt应该是modifiedAt?另外,您确定 all Ref 节点上存在 both 值吗?也许最好在比较之前检查值是否存在。 -
我不确定所有值都存在。条件是“如果 date_one 为 null 或者如果 date_two > date_one 则选择
-
所以有可能定义了 date_one,但是 date_two 为 null 会失败。也许检查 date_two 也不为空。 asg 前缀呢?顺便问一下,您使用的是哪个数据库服务器?
-
date_two 永远不会为空。您可以忘记前缀,这不是这里的问题。问题只是“如果 ref1.date_one 为 null 或 ref1.date_one
标签: java postgresql timestamp gremlin