首页 文章

如何破译此Q / KDB代码

提问于
浏览
0

我需要了解这段代码 .

raze(handle1, handle2, handle3)@\:({.myqueries.select_from_all[`some_table] . (a;b;c;();();0b);p1,p2;`})

基本上,我们的想法是从同一个表中的三个数据库中选择数据 .

@\: 在这种情况下做了什么?为什么 {}() 内?

select_from_all[some_table]之后.` 的含义是什么?

1 回答

  • 4

    看看你提供的代码,看起来可能有些东西丢失了 - 我会告诉你代码所做的预期形式:

    raze(listOfHandles)@\:({[x;y] funcUsingXandY};arg0;arg1)
    
    where:
          listOfHandles - a list of handles to remote processes
          @\: - apply the right hand side to each item in the left hand side list
          ({[x;y] funcUsingXandY};arg0;arg1) - this sends a function definition (lambda) + args for the function, to be executed on each of the handles.
    

    示例(假设有进程侦听localhost,端口7070和7071):

    q) handle1:hopen 7070;
    q) handle2:hopen 7071;
    q) raze(handle1,handle2)@\:({[x;y] enlist(.z.p; x+y)}; 39;3)
        2014.08.23D14:11:15.452611000 42
        2014.08.23D14:11:15.452847000 42
    

    在上面的例子中,我们在每个远程句柄 handle1handle2 上执行带有args (39;3) 的函数 {[x;y] enlist(.z.p; x+y)} - 我们得到当前时间的响应( .z.p )和每个句柄的响应中两个args的总和 . raze 将从每个句柄返回的结果连接到一个列表中(在您的示例中,看起来该函数返回一个表 - 在这种情况下, raze 将连接从句柄返回的表列表到单个表中)

    Edit: 我错过了关于 . 的问题的部分 - . 允许您将参数列表应用于采用多个参数的函数 - 例如:

    q)plus:{[x;y] x+y}
    q)plus . (4;5)
        9
    

    有关详细信息,请参阅:

相关问题