How can I evaluate a Q script in a running KDB server?

僤鯓⒐⒋嵵緔 提交于 2020-01-15 03:28:11

问题


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?


回答1:


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




回答2:


Another option is studioForKdb+ though it does not offer as many features as qstudio http://code.kx.com/wiki/StudioForKdb%2B



来源:https://stackoverflow.com/questions/16616579/how-can-i-evaluate-a-q-script-in-a-running-kdb-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!