键控表 kdb+

问题描述 投票:0回答:1

这是我的tickerplant架构:

sym.q

trade:([]time:`timespan$();sym:`symbol$();price:`float$();size:`long$())

我将根据我的 rdb q 代码中的 sym 为该表设置键。

rdb.q

/q tick/r.q [host]:port[:usr:pwd] [host]:port[:usr:pwd]
/2008.09.09 .k ->.q

if[not "w"=first string .z.o;system "sleep 1"];

upd:upsert;

/ get the ticker plant and history ports, defaults are 5010,5012
.u.x:.z.x,(count .z.x)_(":5010";":5012");

/ end of day: save, clear, hdb reload
.u.end:{t:tables`.;t@:where `g=attr each t@\:`sym;.Q.hdpf[`$":",.u.x 1;`:.;x;`sym];@[;`sym;`g#] each t;};

/ init schema and sync up from log file;cd to hdb(so client save can run)

/ Initialize some tables as keyed tables 
.u.rep:{(.[;();:;].)each x;
    `sym xkey `trade;
    if[null first y;:()];
    -11!y;
    system "cd ",1_-10_string first reverse y};

/ HARDCODE \cd if other than logdir/db

/ connect to ticker plant for (schema;(logcount;log))
.u.rep .(hopen `$":",.u.x 0)"(.u.sub[`;`];`.u `i`L)";

当我运行发布程序时,它会更新插入数据,没有任何错误:

q)trade
sym| time                 price size
---| -------------------------------
ABC| 0D13:50:59.254254870 50    654 

现在我要通过退出该进程并再次启动来测试其重播功能,然后它显示了此错误:

KDB+ 4.0 2023.11.03 Copyright (C) 1993-2023 Kx Systems
l64/ 6(24)core 23967MB naseef naseef-b365m-gaming-hd 127.0.1.1 EXPIRE 2024.08.14 [email protected] KOD #5015621

'type
  [3]  /home/naseef/q/l64/tick/r.q:20: .u.rep:
 if[null first y;:()];
 -11!y;
    ^
 system "cd ",1_-10_string first reverse y}

我也遇到过有两个带键表的情况,但这里没有显示。

如有任何帮助,我们将不胜感激!

database kdb q
1个回答
0
投票

我会避免在模式中键入表并将刻度消息保留到 TP 日志文件中。 (实际上我并不是 100% 确定你能做到)。但是您绝对不能使用 spalyed 表将带键表存储到磁盘(请参见此处 https://code.kx.com/q4m3/14_Introduction_to_Kdb%2B/#142-splayed-tables

“对可以播放的内容有严格的限制。

桌子可以展开。带钥匙的桌子不能。

这似乎排除了关系功能,因为它消除了持久的外键关系。但这一天是由链接列拯救的,它可以被持久化。参见第 14.1.2 节。”

如果您想使用带键表,请将它们存储为无键表,并在加载它们时在 RTS(实时订阅者)或包含业务逻辑的其他服务上对它们进行键控。

希望这有帮助。

如果你挣扎

https://www.defconq.tech/docs/tutorials/tick

© www.soinside.com 2019 - 2024. All rights reserved.