Questions tagged [q-lang]

The q language is a programming language by kx.com for querying kdb+ databases.

Q was developed by Arthur Whitney in 2003 and is built on top of the K programming language. The names q and kdb+ are often used interchangeably, but generally q refers to the programming language and kdb+ refers to the entire runtime environment.

245 questions
1
vote
2 answers

KDB+/Q - over (/) 2 lists of values

How to use "over" on 2 lists of inputs, each time picking 1 element from the 2 lists? E.g., there is: (+/)[1;2 3] = +[+[1;2];3] = 6 How to do something like: f:{x+y+z}; (f/)[1;2 3;22 33] = f[f[1;2;22];3;33] = 61 Thank you.
iwbabn
  • 1,275
  • 4
  • 17
  • 32
1
vote
2 answers

Reduce multiple whitespaces to a single space in KDB+/Q

To get from "a b" to "a b" ssr["a b";"[ ]+";" "] doesn't seem to work. Thanks!
iwbabn
  • 1,275
  • 4
  • 17
  • 32
1
vote
1 answer

[kdb+/q]: Convert adjacency matrix to adjacency list

Given (rectangular) adjacency matrix m, how to construct adjacency list in q language? In QIdioms wiki I've found solution in the k language which when run through q console with k) command gives me 'vs error: m:(1 0 1;1 0 1) k) (^m)_vs…
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
1
vote
1 answer

How to pack/unpack a byte in q/kdb

What I'm trying to do here is pack a byte like I could in c# like this: string symbol = "T" + "\0"; byte orderTypeEnum = (byte)OrderType.Limit; int size = -10; byte[] packed = new byte[symbol.Length + sizeof(byte) + sizeof(int)]; // byte = 1, int =…
Rtrader
  • 917
  • 4
  • 11
  • 26
1
vote
1 answer

Delete column based on type in KDB+

I have a table with a bunch of columns of various types. I need to delete all columns of a particular type, but I can't figure out how to do this. I would like something like this: delete from quotes where type = 11 But this doesn't work. Is there…
1
vote
1 answer

How to update entries in a table within a nested dictionary?

I am trying to create an order book data structure where a top level dictionary holds 3 basic order types, each of those types has a bid and ask side and each of the sides has a list of tables, one for each ticker. For example, if I want to retrieve…
dhk
  • 13
  • 2
1
vote
2 answers

Adding a row to a matrix in Q?

I currently have a 3 by 3 matrix "m": 1 2 3 4 5 6 7 8 9 I would like to add a row to matrix 'm' to have a resultant matrix of: 1 2 3 4 5 6 7 8 9 10 11 12
user3387464
1
vote
1 answer

Format requirements for reading csv files into q/kdb+

(I'm using 32 bit KDB+ 3.3 on OS X.) If I copy and paste the iris dataset into Excel and save it as "MS-DOS Comma Separated (.csv)" and read it into kdb+, I get this: q)("FFFFS";enlist ",")0:`iris.csv 5.1al Length Sepal Width Petal Length Petal…
userABC123
  • 1,460
  • 2
  • 18
  • 31
1
vote
1 answer

Get Column Headers in KDB/q Query

How can i get the just the column headers of a table in KDB? Is there a special query for this? I am asking because when I pull the data from the table into python the column headers are lost. Thanks!
S. Mac
  • 13
  • 2
  • 5
1
vote
2 answers

Is there a way to replay a gzip-compressed log file in kdb+ without uncompressing it first?

Streaming execute, -11!, does not work on named pipes, so an obvious solution of redirecting the gzip -cd output to a named pipe and passing it to -11! does not work.
Alexander Belopolsky
  • 2,228
  • 10
  • 26
1
vote
1 answer

KDB+ / Q Table creation with dynamic number of columns

I am doing stuff like this: q)seed:5 q)numvals:3 q)id:`u#1+til seed; q)vals:numvals cut (seed*numvals)?`8 q)1!([]id;vals) Now I am getting a table like this: id| vals --| -------------------------- 1 | bhlkdkfd ghmjjepm…
Martin Mlostek
  • 2,755
  • 1
  • 28
  • 57
1
vote
1 answer

(kdb+/q): Conversion of `R` datatypes to `q`

Has anyone written a complete conversion of R types to q atomic types? Something like: as.qsymbol <- function(x) UseMethod("as.qsymbol") as.qboolean <- function(x) UseMethod("as.qboolean") as.qsymbol.character <- function(x) …
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
1
vote
1 answer

(kdb+/q) append to dictionary

I am trying to programmatically construct arguments to functional select call having the form: ?[ `t; () ; groupBy; ()] The problematic part is groupBy, which should be a dictionary. Suppose the objective is to arrive at the parse tree in the…
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
1
vote
1 answer

(kdb+/q) Pivot table: date in rows, symbols in columns, last price as values

General pivot function provided at http://code.kx.com/q/cookbook/pivoting-tables/ goes: piv:{[t;k;p;v;f;g] v:(),v; G:group flip k!(t:.Q.v t)k; F:group flip p!t p; count[k]!g[k;P;C]xcols 0!key[G]!flip(C:f[v]P:flip value flip key F)!raze …
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
1
vote
1 answer

Load init.q file at startup

My q.bat file runs fine and it's contents are: g: cd \q w32\q.exe %* -p 5000 Having defined some basic q functions in init.q file, I'd like to have them loaded and available every time I start kdb+/q. I've tried including the below line at the end…
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75