Posts

Showing posts with the label kdb

function return a table in kdb/q

function return a table in kdb/q I'm new in kdb/q and I'm not familiar with kdbq function, hope someone can help me. Here is the question: I have a simple q function declared as the following: func:{[x;y] x+y} And {[x;y] x+y}[3;4] gives me the answer 7 . Everything works perfectly. {[x;y] x+y}[3;4] 7 If I have a table t with two columns such as: t _x _y -------- 3 4 2 5 6 2 ... Could I have a function in q such that compute x+y for each row of table t ? And my expected return would be something like: x+y t res --- 7 7 8 ... Thanks so much! 2 Answers 2 You can just pass the column names as parameters to the function: q)tab:(x:1 2 3;y:4 5 6) q)func:{[x;y] x+y} q) q)select res:func[x;y]from tab res --- 5 7 9 Alternatively you could use functional form to turn that query into a function: q){?[x;();0b;enlist[`res]!enlist(`func;y;z)]}[tab;`x;`y] res --- 5 7 9 ...

Load csv file data into tables

Load csv file data into tables Created tables as below : source:([id:`symbol$()] ric:();source:();Date:`datetime$()) property:([id:`symbol$()] Value:()) Then i have two .csv files which include two tables datas. .csv property.csv showing as below : property.csv id,Value TEST1,1 TEST2,2 source.csv showing as below : source.csv id,ric,source,Date 1,TRST,QO,2017-07-07 11:42:30.603 2,TRST2,QOT,2018-07-07 11:42:30.603 Now , how to load csv file data into each tables one time csv 2 Answers 2 You can use the 0: to load delimited records. https://code.kx.com/wiki/Reference/ZeroColon The most simple form of the function is (types; delimiter) 0: filehandle (types; delimiter) 0: filehandle The types should be given as their uppercase letter representations, one for each column or a blank space to ignore a column. e.g using "SJ" for source.csv would mean I wanted to read in the id column as a sy...