如何评估正在运行的KDB服务器中的Q脚本? [英] How can I evaluate a Q script in a running KDB server?

查看:85
本文介绍了如何评估正在运行的KDB服务器中的Q脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在kdb +服务器中加载要分区的大表.分区代码在我需要在服务器上评估的Q脚本中,但是我没有对其进行I/O控制(服务器在后台运行,内存中的数据通过C API加载). /p>

到目前为止,我发现的唯一解决方案是打开一个句柄并将所有语句转换为字符串(所有这些\我必须使用的外观看起来很杂乱):

if[4 <> count .z.x; 0N!"usage: part_md.q host port db_dir date (YYYY.MM.DD)"; exit[1]]

arg_host: .z.x 0
arg_port: .z.x 1
arg_db_dir: .z.x 2
arg_date: "D"$(.z.x 3)

/get server handle
h:hopen `$(":",arg_host,":",arg_port)
set_db: "db: \":",arg_db_dir, "/mydb/\""
set_sym_path: "sym_path: \":",arg_db_dir,"\""
h set_db
h set_sym_path

/select fields to partition
h "mydb_select: select [-10] A,B,C from mydb"

/enumerate symbols
h "md_select_enum: .Q.en[`$sym_path] md_select"
h "delete md_select from `."
...

如何在不使用同一台计算机上服务器句柄的情况下直接评估我的脚本?

解决方案

您可以使用kStudio IDE,例如qStudio http ://www.timestored.com/qstudio 通过输入命令来发送查询,就像在控制台上一样.

其他一些建议:

  1. 阅读通信间过程的功能形式,这是始终发送字符串的替代方法.功能更强大,因为它允许使用对象.

  2. 避免在变量名中使用下划线,因为它们也是kdb中的运算符. (有关q语言的准则,请参见此处: http://www.timestored.com/kdb-guides/q-coding-standards )

  3. 检出sv函数的许多变体,尤其是(` sv `:file,`name),它允许以与平台无关的方式快速形成文件路径.

关于, 瑞安

I have a large table that I want to partition loaded in a kdb+ server. The partitioning code is in a Q script that I need to evaluate on the server, but I don't have I/O control over it (the server is running in the background, data in memory was loaded through the C API).

So far the only solution I've found is to open a handle and convert all my statements to strings (all those \" I have to use look quite messy):

if[4 <> count .z.x; 0N!"usage: part_md.q host port db_dir date (YYYY.MM.DD)"; exit[1]]

arg_host: .z.x 0
arg_port: .z.x 1
arg_db_dir: .z.x 2
arg_date: "D"$(.z.x 3)

/get server handle
h:hopen `$(":",arg_host,":",arg_port)
set_db: "db: \":",arg_db_dir, "/mydb/\""
set_sym_path: "sym_path: \":",arg_db_dir,"\""
h set_db
h set_sym_path

/select fields to partition
h "mydb_select: select [-10] A,B,C from mydb"

/enumerate symbols
h "md_select_enum: .Q.en[`$sym_path] md_select"
h "delete md_select from `."
...

How can I evaluate my script directly without using a handle to the server on the same machine?

解决方案

You could use a kdb IDE like qStudio http://www.timestored.com/qstudio to send the query by entering commands exactly as you would as if at the console.

Few other suggestions:

  1. Read up on the function form of inter process of communication, an alternative to always sending strings. More powerful as it allows using objects.

  2. Avoid underscores in variable names as they are also operators in kdb. (See here for q language guidelines: http://www.timestored.com/kdb-guides/q-coding-standards )

  3. Checkout the many variations of the sv function, particularly (` sv `:file,`name) it allows quickly forming file paths in a platform independent way.

Regards, Ryan

这篇关于如何评估正在运行的KDB服务器中的Q脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆