Kdb 为每一行分别评估字段上的函数

Kdb evaluate a function on a field separately for every row

我正在尝试 select 来自 table 的描述栏。该列包含字符串,但它们都已入伍,因此它们实际上是包含字符串的 1 元素列表。

我试图通过提取元素 0 来撤消登记。例如:

table:([] id: 1 2 3; name:("Alice"; "Bob"; "Fred"); description: (enlist "wibble"; enlist "something"; enlist "hello"))
select description 0 from table

这会产生

x       
--------
"wibble"

第 1 行 table 不是我想要的。我想要为每一行计算表达式。

您可以使用(参见 http://code.kx.com/q4m3/3_Lists/#310-elided-indices

q)select description[;0] from table
x
-----------
"wibble"
"something"
"hello"

但是您丢失了列名称,除非您手动重命名它。相反(在这种情况下)您可以使用

q)select first each description from table
description
-----------
"wibble"
"something"
"hello"

在这种情况下,您能不能只使用 table 中的 select 描述?正如您所说,描述的每个元素都是一个元素列表

q)select description from table
description
-----------
"wibble"   
"something"
"hello"    
q)

q)\t do[10000;select first each description from table]
66

q)\t do[10000;select description[;0] from table]
63

q)\t do[10000;select description from table]
9

q)a:select first each description from table
q)b:select description[;0] from table
q)c:select description from table

q)type each c
99 99 99h

q)type each b
99 99 99h

q)type each a
99 99 99h