database - 如何在 KDB 中连接展开表?

标签 database kdb q-lang

我在远程服务器上有 2 个非常大(十亿行)的展开表,TradesStockPrices。我想做一个 asof 连接

h:hopen `:RemoteServer:Port
h"aj[`Stock`Date`Time,
        select from Trades where Date within 2014.04.01 2014.04.13,
        StockPrices
    ]"

但我只是得到错误(我是 Studio for KDB+ )

An error occurred during execution of the query.
The server sent the response:
splay
Studio Hint: Possibly this error refers to nyi op on splayed table

那么进行这种连接的正确方法是什么?

此外,对于如此大的表,性能和效率是一个问题——我应该怎么做才能确保查询不会花费数小时并且不会占用服务器系统的大部分资源资源?

最佳答案

您需要将张开的 StockPrices 表映射到内存中。这可以通过使用 select 查询来完成:

q)(`::6060)"aj[`sym`time;select from trade;quote]"                      / bad
   'splay
q)(`::6060)"aj[`sym`time;select from trade;select from quote]"          / good
   sym time         prx      bid      ask
   -------------------------------------------
   aea 01:01:16.347 637.7554 866.0131 328.1476
   aea 01:59:14.108 819.5301 115.053  208.1114
   aea 02:42:44.724 69.38325 641.8554 333.3092

此页面可能有助于从 Kdb+ 查找错误:http://code.kx.com/q/ref/error-list/

关于优化 aj 的性能,请参阅 http://code.kx.com/q/ref/joins/#aj-aj0-asof-join

此外,如果几天之间没有数据重叠,则逐日运行查询可能会更快,可能是并行的。

如果跨天的数据重叠,将日期和时间列合并到一个时间戳列中会加快查找速度。

关于database - 如何在 KDB 中连接展开表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23046109/

相关文章:

mysql - 合并2个MySQL数据库

kdb - 如何在一条语句中多次查询 kdb 表中的同一列?

stock - 如何将 tic 数据转换为 5 分钟 OHLC?

kdb - 调用 string() 时的输出差异

kdb - [KDB+/Q] : Nested vector conditional

r - 在Q中,如何加快Uniicoin采矿?

python - pandas 根据相同日期合并行

SQLite:%midstring% 和 stringstart% 在多个列上搜索,但希望始终首先返回成功的 stringstart% 匹配项

python - MySQL 语法错误?

kdb - 使用结果中的列在 KDB 中创建表