查找 KDB 中具有一组列的所有表

问题描述 投票:0回答:1

我有一个列名称列表。这些是我的环境中不同表中的不同列。我想要创建的是一个字典,其中键具有列,值作为包含该列的表名称列表。

在KDB中有一个简单的方法可以实现它吗?

我正在尝试做如下的事情:-

 colDict:()!()
 CheckColInTables:{[tab;col] colPresent:0b; 
                   colPresent:(col in cols tab);
                   $[ colPresent & (not col in key colDict ); colDict[col]: enlist tab; colDict[col]:colDict[col],enlist ab]; :colDict; };

 GetColTabMapping:{[uniqueCols;tableList] 
                    { tab:x; colDict::CheckColInTables[tab;] each uniqueCols; } each tableList;
                  };

似乎我在调用 CheckColInTables 并更新 colDict 的子函数中传递的 uniqueCols 抱怨不知道 uniqueCols。我尝试将 uniqueCols 分配给 GetColTabMapping 内的变量,然后在内部使用该变量,但这也不起作用。

kdb
1个回答
0
投票

您可以将其简化为:

q)t:([] a:1 2 3;b:4 5 6;c:7 8 9)
q)t1:([] b:1 2 3;c:4 5 6;d:7 8 9)

q){x!y where each x in/:\: cols each y}[`a`b`d`e;tables[]]
a| ,`t
b| `t`t1
d| ,`t1
e| `symbol$()

https://code.kx.com/q/ref/maps/#each-left-and-each-right

© www.soinside.com 2019 - 2024. All rights reserved.