在kdb中使用apply(@)手动创建sym vector
Usage of apply (@) to create sym vector manually in kdb
参考:https://code.kx.com/q4m3/14_Introduction_to_Kdb+/#1422-splayed-tables-with-symbol-columns
在手动进行枚举时,有人可以解释一下如何在下面的示例中使用 @ 创建 sym 向量吗?
示例:
我已经打开了一个新的 q 实例:
q)t:([] s1:`a`b`c; v:10 20 30; s2:`x`y`z)
q)@[t;exec c from meta t where "s"=t;`sym?] /- Creates a sym vector in memory
q)sym
/- Output - `a`b`c`x`y`z
q)type sym
/- Output - 11h
编辑-
明白了,是 apply at
在做这项工作,它等于使用 apply at 更新列表。
例如:
q)l:2 3 9
q)@[l;1;neg]
2 -3 9
同样,我们基于条件将枚举扩展到符号向量作为第二个参数,即 table t
的所有符号列
@[t;exec c from meta t where t="s";`sym?]
执行此操作的 @ (amend) operator is not what generates the `sym
vector, it's the ? (Enum Extend) 运算符。
上面的 @
将 `sym?
应用于 t
的所有列,它们是符号类型。您可以自己直接应用它并生成 `sym
:
q)show t:([] s1:`a`b`c; v:10 20 30; s2:`x`y`z)
s1 v s2
--------
a 10 x
b 20 y
c 30 z
q)sym
'sym
[0] sym
^
q)`sym?t`s1
`sym$`a`b`c
q)sym
`a`b`c
q)`sym?t`s2
`sym$`x`y`z
q)sym
`a`b`c`x`y`z
`sym
在我们第一次调用该函数时创建,并在我们再次调用时继续扩展。
参考:https://code.kx.com/q4m3/14_Introduction_to_Kdb+/#1422-splayed-tables-with-symbol-columns
在手动进行枚举时,有人可以解释一下如何在下面的示例中使用 @ 创建 sym 向量吗?
示例:
我已经打开了一个新的 q 实例:
q)t:([] s1:`a`b`c; v:10 20 30; s2:`x`y`z)
q)@[t;exec c from meta t where "s"=t;`sym?] /- Creates a sym vector in memory
q)sym
/- Output - `a`b`c`x`y`z
q)type sym
/- Output - 11h
编辑-
明白了,是 apply at
在做这项工作,它等于使用 apply at 更新列表。
例如:
q)l:2 3 9
q)@[l;1;neg]
2 -3 9
同样,我们基于条件将枚举扩展到符号向量作为第二个参数,即 table t
的所有符号列@[t;exec c from meta t where t="s";`sym?]
执行此操作的 @ (amend) operator is not what generates the `sym
vector, it's the ? (Enum Extend) 运算符。
@
将 `sym?
应用于 t
的所有列,它们是符号类型。您可以自己直接应用它并生成 `sym
:
q)show t:([] s1:`a`b`c; v:10 20 30; s2:`x`y`z)
s1 v s2
--------
a 10 x
b 20 y
c 30 z
q)sym
'sym
[0] sym
^
q)`sym?t`s1
`sym$`a`b`c
q)sym
`a`b`c
q)`sym?t`s2
`sym$`x`y`z
q)sym
`a`b`c`x`y`z
`sym
在我们第一次调用该函数时创建,并在我们再次调用时继续扩展。