从面向网络的数据库将 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 名称)。
问题包括:
table 很大。如果需要,我准备在我的机器上等待,但我确实需要它最终工作。
虽然我可以获得所有服务器 table 名称的清晰列表,但我永远无法以有用的格式获取它(理想情况下它是一个列表,而不是hopen-ed [tables] 命令总是给我的符号)。另外,我被告知可能无需明确查询 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
我所拥有的:hostname/port 总是 运行ning [q] 会话的数量,它通过我们的内部网络公开了多个 KDB table。我可以在浏览器中轻松地对它执行 运行 [q] 命令(或者甚至通过使用 [hopen],通过在命令行上调用的本地 [q] 会话)。
我需要的是:一个 [q] 脚本,或者知道如何编写脚本,它将自动连接到面向 Web 的数据库,并将其所有 table 复制到本地主机[q] 会话的工作记忆(无需 提前知道所有 table 名称)。
问题包括:
table 很大。如果需要,我准备在我的机器上等待,但我确实需要它最终工作。
虽然我可以获得所有服务器 table 名称的清晰列表,但我永远无法以有用的格式获取它(理想情况下它是一个列表,而不是hopen-ed [tables] 命令总是给我的符号)。另外,我被告知可能无需明确查询 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