从面向Web的数据库中将KDB表下载到[q]会话中

时间:2018-06-20 02:20:37

标签: kdb

我所拥有的:一个始终运行的[q]会话的主机名/端口号,该会话通过我们的内部网站公开了多个KDB表。我可以在浏览器中轻松地对它运行[q]命令(甚至通过使用[hopen],通过在命令行上调用的本地[q]会话)。

我需要什么:一个[q]脚本,或者如何编写脚本的知识,该脚本将自动连接到面向Web的数据库,并将其所有表复制到localhost [q]会话的工作内存中( 无需提前知道所有表名)。

关注的问题包括:

  • 表很大。我准备在需要时在我的机器上等待,但是最终我确实需要这样做。

  • 虽然我可以获得所有服务器表名的清晰列表,但我永远无法以有用的格式获得它(理想情况下,它应该是一个List,而不是希望的[tables]的Symbol ]命令总是给我)。另外,有人告诉我,即使不显式查询表名也可以完成传输,尽管我无法想象如何实现。奖励积分(如果您管理的话)

1 个答案:

答案 0 :(得分:1)

Yo可以这样实现顺畅:

.data.oc:1000;

/connect to the session using hopen
h:hopen `::1234;

/get the table names
tabs:h"tables[]";

/create local tables with the same names
{ .[x;();:;()] } each tabs;

/for each table name
{[tab]

     /get the table count
    c:h({count value x};tab);

    oc:.data.oc;
    /cut the table count to some optimal value, say 10,000 (0-99999; 10000-19999).
    idxl:$[c>oc; [ l: c div  oc; ( (0;oc-1)+/:oc*til l),enlist (l*oc;c-1)  ] ; enlist (0; c-1)];

    /now iterate over the list and use them as indexes to query the table.
    {[t;idx] t upsert h ({[t;y] ?[t; enlist (within;`i;y);0b;()] } ; t;idx ) }[tab] each  idxl;

 }each tabs