从 kdb 中的嵌套 table 中删除键列表
Drop a list of keys from a nested table in kdb
我正在尝试从嵌套的 table 中删除一组项目;例如给出以下 table
tree:{[t;col]
if[1=count col; :![t;();0b;enlist[`name]!col]];
f:first col;
c:cols[t] except f;
r:1_col;
:?[t;();(enlist `name)!enlist f ;`val`child!((sum;`val);({[r;c;l] tree[flip c!l;r]};enlist r;enlist c;(enlist, c )))]
};
t:flip`cat`dog`caps`val`val1!flip((cross/)(0 1;`$(5 1)#.Q.a;`$(5 1)#.Q.A;til 5;5+til 5));
// derive tree from aforementioned table
tre:tree[t;`cat`dog`caps];
// notably returns correct result indexed by name
.[tre;(0;`child)] enlist[`name]!enlist[`a`b`c];
// does not work ???
.[tre;(0;`child);_;enlist[`name]!enlist[`a`b`c]];
我想过用下面的方法解决
.[tre;(0;`child);{delete from y where name in x}[`a`b`c]];
我只是想看看有没有更简洁(普遍接受)的方法。比如使用enlist[name]!enlist[
ab
c];实现这一目标的索引。
在 KDB+ 中,应该如何适当地从嵌套树中删除一组给定的索引?
感谢您的指导。
假设你想要改变这个:
像这样,即删除 a、b 和 c 的条目:
您可以稍微修改您的代码以像这样使用 Over:
.[tre;(0;`child);_/;`a`b`c]
这将根据需要对每个键应用删除。
我喜欢shree.pat的解决方案!只是补充说,如果您稍作修改,您最初的尝试可能会奏效:
q).[tre;(0;`child);{y _ x};flip enlist[`name]!enlist[`a`b`c]]
name| val child ..
----| -----------------------------------------------------------------------..
0 | 1250 (+(,`name)!,`d`e)!+`val`child!(250 250;(+`caps`val`val1`name!(`A`A..
1 | 1250 (`s#+(,`name)!,`s#`a`b`c`d`e)!+`val`child!(250 250 250 250 250;(+`..
我正在尝试从嵌套的 table 中删除一组项目;例如给出以下 table
tree:{[t;col]
if[1=count col; :![t;();0b;enlist[`name]!col]];
f:first col;
c:cols[t] except f;
r:1_col;
:?[t;();(enlist `name)!enlist f ;`val`child!((sum;`val);({[r;c;l] tree[flip c!l;r]};enlist r;enlist c;(enlist, c )))]
};
t:flip`cat`dog`caps`val`val1!flip((cross/)(0 1;`$(5 1)#.Q.a;`$(5 1)#.Q.A;til 5;5+til 5));
// derive tree from aforementioned table
tre:tree[t;`cat`dog`caps];
// notably returns correct result indexed by name
.[tre;(0;`child)] enlist[`name]!enlist[`a`b`c];
// does not work ???
.[tre;(0;`child);_;enlist[`name]!enlist[`a`b`c]];
我想过用下面的方法解决
.[tre;(0;`child);{delete from y where name in x}[`a`b`c]];
我只是想看看有没有更简洁(普遍接受)的方法。比如使用enlist[name]!enlist[
ab
c];实现这一目标的索引。
在 KDB+ 中,应该如何适当地从嵌套树中删除一组给定的索引? 感谢您的指导。
假设你想要改变这个:
像这样,即删除 a、b 和 c 的条目:
您可以稍微修改您的代码以像这样使用 Over:
.[tre;(0;`child);_/;`a`b`c]
这将根据需要对每个键应用删除。
我喜欢shree.pat的解决方案!只是补充说,如果您稍作修改,您最初的尝试可能会奏效:
q).[tre;(0;`child);{y _ x};flip enlist[`name]!enlist[`a`b`c]]
name| val child ..
----| -----------------------------------------------------------------------..
0 | 1250 (+(,`name)!,`d`e)!+`val`child!(250 250;(+`caps`val`val1`name!(`A`A..
1 | 1250 (`s#+(,`name)!,`s#`a`b`c`d`e)!+`val`child!(250 250 250 250 250;(+`..