OSQL中的OrientDB日期操作以找到同一天但不同年份的节点的路径 [英] OrientDB date manipulation in OSQL to find a path with nodes on the same day but different years

查看:53
本文介绍了OSQL中的OrientDB日期操作以找到同一天但不同年份的节点的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个结构如下图:

A --> B

A 有一个日期字段.

这仍然基于与我的另一个问题,但这不同之处在于我不关心尝试在一个 OSQL 调用中完成所有操作以创建边缘.在这种情况下,我只是想生成一个看起来像这样的路径:

This is still based on the same problem as in my other question, but this differs in that I'm not concerned with trying to do everything in one OSQL call to create edges. In this case, I'm only trying to generate a path that looks like:

A1(日期=2014-01-01)---> B <--- A2(日期=2013-01-01)

A1 (date=2014-01-01) ---> B <--- A2 (date=2013-01-01)

并返回一个只包含 A1 和 A2 id 的表.

And return a table containing just the A1 and A2 id's.

我已经开始处理一个类似如下的 MATCH 查询:

I've started working up a MATCH query that looks like:

MATCH {CLASS: A, AS: A1} -edgeTypeA->
  {AS: B} <-edgeTypeA-
  {AS: A2, WHERE: {$matched.A1.Date=$currentMatch.Date}
RETURN A1, B, A2

这有效,但它只返回基本上 A1 和 A2 是完全相同日期的匹配项(包括 A1 和 A2 是相同节点的地方).

This works but it's only returning matches where basically A1 and A2 are the exact same date (including where A1 and A2 are the same node).

我知道我可以使用 format() 提取日期字段的一部分...例如,如果我只想要一个包含年份的字符串,我可以使用 $currentMatch.Date.format('yyyy') 来获取它,但是我仍然没有想出如何为查询目的增加该日期.

I know I can extract parts of a date field using format()... for example, if I just want a string containing the year I could use $currentMatch.Date.format('yyyy') to get that but I still haven't figured out how to increment that date for the purposes of my query.

推荐答案

我在看到 Alessandro 在我的旧问题中做了什么.我正在添加我的解决方案用于存档目的.希望它可以帮助需要在 OSQL 查询中进行日期操作的其他人.

I got it working after seeing what Alessandro did in my old question. I'm adding my solution for archival purposes. Hopefully it might help others down the line who need to do date manipulation within OSQL queries.

这是我最后的结果:

MATCH {CLASS: A, AS: A1} -edgeTypeA->
    {AS: B} <-edgeTypeA-
    {AS: A2, WHERE: ($matched.A1.Date.format('yyyy').asInteger()=sum($currentMatch.Date.format('yyyy').asInteger(),-1) AND
                     $matched.A1.Date.format('MM-dd')=$currentMatch.Date.format('MM-dd') ) }
RETURN A1,A2

而且我得到了适合我的数据的东西:

and I get the right thing for my data:

+----+------+------+
|#   |A1    |A2    |
+----+------+------+
|0   |#49:30|#49:32|
|1   |#55:44|#56:46|
|2   |#53:0 |#53:2 |
|3   |#55:20|#55:22|
|4   |#49:42|#49:44|
|5   |#50:32|#50:34|
+----+------+------+

不得不调用 sum 的感觉有点像()asInteger() 但现在我明白了它并且可以使用它.

It kind of feels like a lot to have to make the call to sum() and asInteger() but now I understand it and can work with that.

这篇关于OSQL中的OrientDB日期操作以找到同一天但不同年份的节点的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆