TorQ:如何使用具有不同日期范围的单独表格进行数据加载器分区?

时间:2017-12-14 13:29:26

标签: kdb torq

我尝试使用AquaQ的TorQ来填充价格并引用数据库。为此,我使用.loader.loadallfiles function。区别在于prices是每日数据而quotes更多是在日内,例如外汇汇率。

我按如下方式进行加载:

/- check the location of database directory
hdbdir:hsym `$getenv[`KDBHDB]
/hdbdir:@[value;`hdbdir;`:hdb]
rawdatadir:hsym `$getenv[`KDBRAWDATA]

target:hdbdir;

rawdatadir:hsym `$("" sv (getenv[`KDBRAWDATA]; "prices"));
.loader.loadallfiles[`headers`types`separator`tablename`dbdir`partitioncol`partitiontype`dataprocessfunc!(`date`sym`open`close`low`high`volume;"DSFFFFF";enlist ",";`prices;target;`date;`year;{[p;t] `date`sym`open`close`low`high`volume xcols update volume:"i"$volume from t}); rawdatadir];

rawdatadir:hsym `$("" sv (getenv[`KDBRAWDATA]; "quotes"));
.loader.loadallfiles[`headers`types`separator`tablename`dbdir`partitioncol`partitiontype`dataprocessfunc!(`date`sym`bid`ask;"ZSFF";enlist ",";`quotes;target;`date;`year;{[p;t] `date`sym`bid`ask`mid xcols update mid:(bid+ask)%2.0 from t}); rawdatadir];

这很好用。但是,在加载数据库时,我会收到错误,要求从任一表中进行选择。原因是对于某些分区,没有任何prices或者没有任何quotes数据。例如试图:

quotes::`date`sym xkey select from quotes;  

失败并显示错误说明年份的分区,例如hdb/2000/不存在,这是真的,2000年只有prices而没有quotes

我认为有两种可能的解决方案但我不知道如何实施:

  1. 告诉.loader.loadallfiles为没有任何数据的分区中的报价和价格创建空架构。
  2. 在加载数据库时,优雅地处理给定分区没有数据的情况,即select from ... where ignore empty partitions

1 个答案:

答案 0 :(得分:1)

尝试使用.Q.chk[`:hdb]

`:hdb是HDB的文件路径

这会填写缺失的表格,然后允许您预先形成查询。

或者,您可以使用.Q.bv,其中wiki说明:

  

如果您的表存在于最新的分区中(因此有一个原型   对于模式),然后您可以使用.Q.bv[]来创建空表   在运行时即时运行而无需在磁盘上创建这些空。