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

Downloading KDB tables into a [q] session from a web-facing database

我所拥有的:hostname/port 总是 运行ning [q] 会话的数量,它通过我们的内部网络公开了多个 KDB table。我可以在浏览器中轻松地对它执行 运行 [q] 命令(或者甚至通过使用 [hopen],通过在命令行上调用的本地 [q] 会话)。

我需要的是:一个 [q] 脚本,或者知道如何编写脚本,它将自动连接到面向 Web 的数据库,并将其所有 table 复制到本地主机[q] 会话的工作记忆(无需 提前知道所有 table 名称)。

问题包括:

你可以这样实现:

.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