获取大型 tplog 文件的子集,而无需将完整的 tplog 文件加载到 kdb 的内存中

Get subset of a large tplog file without loading the complete tplog file in memory in kdb

我有一个几百 GB 的 tplog 文件,其中包含许多 table 的日志 - 'trade'、'quote' 等
我想将包含交易记录的 tplog 文件 table 创建到磁盘上的新 tplog 文件 (tradeTpLog) 中。
由于我的 tplog 文件很大,因此不可能一次加载完整的 tplog 文件,所以我想从内存中的 tplog 文件中读取单个 record/chunck 记录,然后检查 table 是否 'trade' 如果是,则将记录附加到磁盘上的 tradeTpLog 文件。

测试TpLog文件记录:

2#get `:./sym2020.05.13
((`upd;`trade;(20:46:39.781823000 20:46:39.781823000;`GS.N`BA.N;178.5163025 128.0462196;798 627j));(`upd;`quote;(20:46:39.782805000 20:46:39.782805000;`IBM.N`VOD.L;191.0897744 341.2843914;191.1130483 341.3052296;564 807j;886 262j)))

我知道-11!我们可以向其中提供 n 个元素,但不确定 if/how 在这种情况下是否可以使用它。

尝试失败:

{if[`trade~x@1;`:./tradeFile upsert x]}@'25#get `:./sym2020.05.13

您不能有选择地从日志中提取行,但您可以只更新 upd 的定义。如果你想创建一个新的日志文件你不能使用upsert,你需要创建一个新的日志文件

// Preserve the original upd functionality
upd_old::upd;
// Create a new log file and a handle to use
`:tradeLog set ();
h::hopen `:tradeLog;
// Define a new upd 
upd:{[t;x] if[t=`trade;h enlist (`upd;t;x)]};
// Replay the log file
-11!`:./sym2020.05.13;
// Revert the upd functionality
upd::upd_old

使用-11!将比 get.

快得多

如果需要,您可以选择通过 -11!(n;x)

重播 n 个元素