【发布时间】:2019-03-17 19:02:17
【问题描述】:
我希望能够从远程存储在磁盘上的非常大的键控表中批量选择行。作为测试我的功能的玩具示例,我设置了以下表格 t 和 nt...
t:([sym:110?`A`aa`Abc`B`bb`Bac];px:110?10f;id:1+til 110)
nt:0#t
我从表中只选择以字符“A”开头的记录,计算字符数,将计数除以我想为每个函数调用获取的行数 (10),然后向上取整到最接近的整数...
aRec:select from t where sym like "A*"
counter:count aRec
divy:counter%10
divyUP:ceiling divy
接下来我将idx 变量设置为0,并将if statement 作为参数化函数。这将检查 idx 是否等于 divyUP。如果不是,那么它应该选择 aRec 的前 10 行,将它们插入到 nt 表中,将函数参数 x 递增 10,并将 idx 变量递增 1。一旦 @ 987654333@ 变量和divyUP 相等应该退出函数...
idx:0
batches:{[x]if[not idx=divyUP;batch::select[x 10]from aRec;`nt upsert batch;x+:10;idx+::1]}
但是,当我调用该函数时,它会返回 type 错误...
q)batches 0
'type
[1] batches:{[x]if[not idx=divyUP;batch::select[x 10]from aRec;`nt upsert batch;x+:10;idx+::1]}
^
我也尝试过将它与sublist 一起使用,尽管我得到了相同的结果...
batches:{[x]if[not idx=divyUP;batch::x 10 sublist aRec;`nt upsert batch;x+:10;idx+::1]}
q)batches 0
'type
[1] batches:{[x]if[not idx=divyUP;batch::x 10 sublist aRec;`nt upsert batch;x+:10;idx+::1]}
^
但是在函数之外发出上述任何一个命令都返回预期的结果...
q)select[0 10] from aRec
sym| px id
---| ------------
A | 4.236121 1
A | 5.932252 3
Abc| 5.473628 5
A | 0.7014928 7
Abc| 3.503483 8
A | 8.254616 9
Abc| 4.328712 10
A | 5.435053 19
A | 1.014108 22
A | 1.492811 25
q)0 10 sublist aRec
sym| px id
---| ------------
A | 4.236121 1
A | 5.932252 3
Abc| 5.473628 5
A | 0.7014928 7
Abc| 3.503483 8
A | 8.254616 9
Abc| 4.328712 10
A | 5.435053 19
A | 1.014108 22
A | 1.492811 25
【问题讨论】:
标签: kdb