kdb

[KDB+/Q]: Deparse q parse tree into q expression (string)

若如初见. 提交于 2020-01-15 11:14:03
问题 Let's define deparse 1 as inverse operation to q's native parse , so that the following holds: q)aStringQExpression~deparse parse aStringQExpression 1b Question What's the definition of deparse function so that the above indeed works? For example, in the below update expression, we know that "a*0^b+c-d" expression corresponds to (*;`a;(^;0;(+;`b;(-;`c;`d)))) parse tree: q)-3!parse "update col:a*0^b+c-d from t" "(!;`t;();0b;(,`col)!,(*;`a;(^;0;(+;`b;(-;`c;`d)))))" So the envisaged deparse

How to do a between join clause in KDB?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-15 10:21:50
问题 Suppose I have a table A with the columns bucket_start_date, bucket_end_date, A bucket_start_date | bucket_end_date 2015.05.02 | 2015.05.08 2015.05.08 | 2015.05.12 Also suppose i have a table B with the columns date, coins. A date | coins 2015.05.02 | 5 2015.05.06 | 11 2015.05.09 | 32 How do I do a join in kdb that logically looks like select A.bucket_start_date, A.bucket_end_date, sum(coins) from A join B where B.date BETWEEN A.bucket_start_date and A.bucket_end_date group by A.bucket_start

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)";

q - apply function on table rowwise

我是研究僧i 提交于 2020-01-14 05:30:28
问题 Given a table and a function t:([] c1:1 2 3; c2:`a`b`c; c3:13:00 13:01 13:02) f:{[int;sym;date] symf:{$[x=`a;1;x=`b;2;3]}; datef:{$[x=13:00;1;x=13:01;2;3]}; r:int + symf[sym] + datef[date]; r }; I noticed that when applying the function f onto columns of t , then the entire columns are passed into f and if they can be operated on atomically then the output will be of the same length as the inputs and a new column is produced. However in our example this wont work: update newcol:f[c1;c2;c3]

soft deleting a column from a table in q

。_饼干妹妹 提交于 2020-01-06 08:20:08
问题 I am trying to delete a column from a table without the loss of data so the data can be reinstated again but when the table is loaded up by q process the deleted column will not show. Obviously my code below will not work. Is there something specific to q that can do that? dir is where the table is and c is the column to be deleted. {[dir;t;c] delete c from (` sv (dir,t),`)} 回答1: kdb+ has an easy way to "remove" a column without actually deleting the column data. If you look in the directory

KDB/q: How to update a table with row containing disparate columns?

寵の児 提交于 2020-01-05 04:24:06
问题 I'm trying to update a table (A) with a secondary table/row(B) as follows: table:() row:([]x:`val1;) table upsert row table insert row Which works when all subsequent rows have the same schema. However an edge case I'm trying to account for relates to when the subsequent rows could be of a different schema i.e.: row:([]x:`val1;y:`val2) The above throws a mismatch error which would be expected. How do I modify the above insert/upsert logic to account for the advent of updates with a different

Rolling window in multi groups

自闭症网瘾萝莉.ら 提交于 2020-01-03 05:39:08
问题 I have the following trade table: time ticker side price qty -------------------------- 2018.01.01T13:00:20 AAPL BUY 10.0 100 2018.01.01T13:01:30 AAPL SELL 12.0 300 2018.01.01T13:01:45 AAPL BUY 11.0 500 2018.01.01T13:02:13 AAPL BUY 10.5 100 2018.01.01T13:05:00 AAPL SELL 13.0 200 I need a rolling window function with a lookback of 1 minute to seperate the buy/sells of a stock price time ticker BUYs SELLs TOTAL -------------------------------- 2018.01.01T13:00:20 AAPL 1 0 1 2018.01.01T13:01:30

kdb+: Save table into a csv file

半城伤御伤魂 提交于 2020-01-02 11:27:11
问题 I have the below table "dates" , it has a sym column with symbols and a d column with list of strings and would like to save it into a regular CSV file. Couldn't find a good way to do it. Any suggestions? q)dates sym d ---------------------------------------------------------------------------- 6AH0 "1970.03.16" "1980.03.17" "1990.03.19" "2010.03.15" 6AH6 "1976.03.15" "1986.03.17" "1996.03.18" "2016.03.14" 6AH7 "1977.03.14" "1987.03.16" "1997.03.17" "2017.03.13" 6AH8 "1978.03.13" "1988.03.14"

How to join strings in a table in kdb?

余生颓废 提交于 2019-12-25 17:26:15
问题 I would like to join string in kdb but didn't work well. This is the data: tab:([]service:`CS`CS.US`CS.US_ABC;y:1 2 3) `CS 1 `CS.US 2 `CS.US_ABC 3 I would like to add :0 and :primary depending on the given parameter. 0 is working now update service:`$(((string[service],'(":"))),'("C"$string 0)) from tab If I would like the data to become `CS:primary 1 `CS.US:primary 2 `CS.US_ABC:primary 3 and the primary is either string or symbol, how could I join? I am parameterizing the 0 and primary.

qpython.sync() is returning a QProjection instead of the queried data

倖福魔咒の 提交于 2019-12-25 08:49:45
问题 So I am running the following query without problems: print(self.data_source.connections['history'].sync( '{[x;y;z]select from trade where date within(x;y), sym in z}', numpy.datetime64('2014-04-14', 'D'), numpy.datetime64('2017-08-14', 'D'), NumpyUtil.parse_symbols(['instr81', 'instr61', 'instr26']) )) Here the self.data_source.connections[] is just a dictionary with the tickerplant, hdb and rdb connections and the NumpyUtil.parse_symbols() is a little method that parses the argument to the