xbar,最后一个关键字并从 table 列中减去

xbar, last keyword and subtract from table column

a:([]time:(2021.01.31D22:18:00.000000000;2021.01.31D22:18:27.134000000;2021.01.31D22:18:27.834000000;2021.01.31D22:21:14.284000000);val:(3.2;2.9;3.9;6.8))

time                          val
---------------------------------
2021.01.31D22:18:00.000000000 3.2
2021.01.31D22:18:27.134000000 2.9
2021.01.31D22:18:27.834000000 3.9
2021.01.31D22:21:14.284000000 6.8

a1:select last val by 0D00:01 xbar time from a
time                         | val
-----------------------------| ---
2021.01.31D22:18:00.000000000| 3.9
2021.01.31D22:21:00.000000000| 6.8

a2:update diff:val - last val by 0D00:01 xbar time from a

time                          val diff
--------------------------------------
2021.01.31D22:18:00.000000000 3.2 -0.7
2021.01.31D22:18:27.134000000 2.9 -1  
2021.01.31D22:18:27.834000000 3.9 0   
2021.01.31D22:21:14.284000000 6.8 0  

对于a2中的第2行、第3行,当a1中没有匹配的时间值时,q查询如何保证将val列减去对应分钟的“last”val?是否有一般规则来理解此处 xbar 的使用或我可以阅读的类似示例的任何参考?

感谢您的帮助。

这种替代方法应该可以帮助您了解 xbar 分组的工作原理:

q)ungroup{update diff:val-last val from x}each`grouper xgroup update grouper:0D00:01 xbar time from a
grouper                       time                          val diff
--------------------------------------------------------------------
2021.01.31D22:18:00.000000000 2021.01.31D22:18:00.000000000 3.2 -0.7
2021.01.31D22:18:00.000000000 2021.01.31D22:18:27.134000000 2.9 -1
2021.01.31D22:18:00.000000000 2021.01.31D22:18:27.834000000 3.9 0
2021.01.31D22:21:00.000000000 2021.01.31D22:21:14.284000000 6.8 0