KDB/q 将两个参数列表传递给一个函数

KDB/q pass two list of arguments to a function

提问人:VUM 提问时间:10/31/2023 更新时间:10/31/2023 访问量:79

问:

嗨,最近开始学习KDB,我正在尝试执行如下操作,感谢您帮助简化它。

q)f:{[x;dt] flip `Destination`Session`Time!(3#last ` vs x;`start`mid`end;("P"$(string dt),"D","01:15:00.000000000";"P"$(string dt),"D","01:30:00.000000000";"P"$(string dt),"D","06:57:00.000000000")) }

q)dt:.z.d+til 5
q)f1:{f[x;y]} each `AAA`BBB`CCC`DDD
q)raze{raze f1[x]} each dt
KDB Q

评论


答:

3赞 Thomas Smyth - Treliant 10/31/2023 #1

为此,可以使用每个字形 '

raze raze f'[`AAA`BBB`CCC`DDD]'[dt]

评论

1赞 terrylynch 11/1/2023
也可能是类似的raze raze`AAA`BBB`CCC`DDD f\:/:dt
2赞 Cathal O'Neill 10/31/2023 #2

如果表格的顺序无关紧要,这里有另一种选择

q)x:`AAA`BBB`CCC`DDD
q)ses:`start`mid`end
q)dt:2023.10.31 2023.11.01 2023.11.02 2023.11.03 2023.11.04
q)tms:01:15 01:30 06:57
q)ungroup flip`Destination`Session`Time!flip x cross ses,'enlist each dt+/:tms
Destination Session Time
-------------------------------------------------
AAA         start   2023.10.31D01:15:00.000000000
AAA         start   2023.11.01D01:15:00.000000000
AAA         start   2023.11.02D01:15:00.000000000
AAA         start   2023.11.03D01:15:00.000000000
AAA         start   2023.11.04D01:15:00.000000000
AAA         mid     2023.10.31D01:30:00.000000000
AAA         mid     2023.11.01D01:30:00.000000000
AAA         mid     2023.11.02D01:30:00.000000000
AAA         mid     2023.11.03D01:30:00.000000000
AAA         mid     2023.11.04D01:30:00.000000000
AAA         end     2023.10.31D06:57:00.000000000
AAA         end     2023.11.01D06:57:00.000000000
AAA         end     2023.11.02D06:57:00.000000000
AAA         end     2023.11.03D06:57:00.000000000
AAA         end     2023.11.04D06:57:00.000000000
..

还值得注意的是,无需使用字符串在表中创建时间戳

f:{[x;dt] flip `Destination`Session`Time!(3#last ` vs x;`start`mid`end;("P"$(string dt),"D","01:15:00.000000000";"P"$(string dt),"D","01:30:00.000000000";"P"$(string dt),"D","06:57:00.000000000")) }

相当于

f:{[x;dt] flip `Destination`Session`Time!(3#x;`start`mid`end;(dt+01:15 01:30 06:57))}