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
4 answers

Functional addition of Columns in kdb+q

I have a q table in which no. of non keyed columns is variable. Also, these column names contain an integer in their names. I want to perform some function on these columns without actually using their actual names How can I achieve this ? For…
pikachuchameleon
  • 665
  • 3
  • 10
  • 27
1
vote
1 answer

Multiple union joins in kdb

I have a task in which I need to do Union Joins of variable no. of tables. As of now, I've stored all the tables in a list. How can I do a multiple union joins of all the tables using adverb ? Example: L:(table1,table2,table3) // I need something…
pikachuchameleon
  • 665
  • 3
  • 10
  • 27
1
vote
2 answers

How to join multiple tables

I'm trying to join multiple tables in q a b c key | valuea key | valueb key | valuec 1 | xa 1 | xb 2 | xc 2 | ya 2 | yb 4 | wc …
Rob
  • 793
  • 1
  • 7
  • 8
1
vote
1 answer

How to get positions of element matches in a list in kdb?

For instance, if I have a list a:2 5 3 1, I can match another list against it, say b:3 5, which matches the 3 at a[2] and the 5 at a[1]. I am interested in getting my hands on the indices 2 1. I tried where 3 5 in 2 5 3 1 but didn't work.
mchen
  • 9,808
  • 17
  • 72
  • 125
1
vote
1 answer

KDB, comparing values produced by two different systems within time period

I have two different systems pushing data into a kdb table. These are driven by a feed of prices. I'd like to compare the values produced so I can ultimately flag large differences. I'm very new to kdb though and finding it hard to even work out a…
1
vote
2 answers

General position find function in q

I need something like Position function for Mathematica (http://reference.wolfram.com/mathematica/ref/Position.html) but in Q. My solution for rectangular matrix is following: q) colrow:{sz:count x; $[(count first x) = 1; enlist y; (floor y % sz; y…
mde
  • 334
  • 4
  • 9
1
vote
1 answer

How can I elide top level index in functional amend

.[string 10#.z.d;(til 10;4 7);:;"-"] Does what I want; it replaces char 4 and 7 for each element in a list of dates with "-". I seem to remember it being possible to elide the top level index (i.e. til 10) in some way. I would expect the below to…
mollmerx
  • 648
  • 1
  • 5
  • 18
1
vote
4 answers

Interpret line of Q code

Trying to understand what this function does: yr:{ yr:.z.T+1000*x; -1 string .z.Z; while[(.z.T < yr); ZZ,::.z.Z]} I understand .z.Z gets the datetime, and that execution is from right to left. what is ZZ? What is .z.T? Essentially, what does the…
stretchr
  • 615
  • 2
  • 9
  • 24
1
vote
2 answers

Char vs Symbol KDB parted splay table

I am creating a new table on a KDB database as a parted splay (parted by date), the new table schema has a column called CCYY, which has a lot of repeating values. I am unsure if I should save it as char or symbols. My main goal is to use least…
stretchr
  • 615
  • 2
  • 9
  • 24
1
vote
1 answer

How to join splayed table in KDB?

I have 2 very large (billions of rows) splayed tables, Trades and StockPrices, on a remote server. I want to do an asof join h:hopen `:RemoteServer:Port h"aj[`Stock`Date`Time, select from Trades where Date within 2014.04.01 2014.04.13, …
mchen
  • 9,808
  • 17
  • 72
  • 125
1
vote
1 answer

KDB asof join giving incorrect results

I have a table of trades Trades: TradeID Stock Timestamp 1 GOOG 2014.03.03 09:13:59.054 2 GOOG 2014.03.03 09:28:12.003 3 GOOG 2014.03.03 09:28:18.199 4 GOOG 2014.03.03 09:52:03.628 5 GOOG 2014.03.03…
mchen
  • 9,808
  • 17
  • 72
  • 125
1
vote
3 answers

kdb c++ interface: string representation of k object

Is there a way to get string representation of k object, similar (better identical) to that printed to q console? q)([]a:`a`b`c;b:"abc";c:1 2 3) a b c ----- a a 1 b b 2 c c 3 q)
user443854
  • 7,096
  • 13
  • 48
  • 63
1
vote
2 answers

kdb: Add a column showing sum of rows in a table with dynamic headers while ignoring nulls

I have a table whose columns are dynamic, except one column:A. The table also has some null values (0n) in it. How do I add another column that shows total of each row and either ignores the column that has "0n" in that particular row or takes 0 in…
user2696565
  • 587
  • 1
  • 8
  • 17
1
vote
1 answer

kdb Q date from string

I have a csv file with four columns that contain a date. StartDate, EndDate, ActionDate, MaturityDate 18/01/2013, 18-01-2013, 18-01-2013 07:59 PM, 18-01-2013 19:59 I am loading this into a table with: myTable:("DDDD";enlist ",") 0:…
Eric
  • 295
  • 2
  • 7
  • 22
1
vote
2 answers

kdb c++ interface: create byte list from std::string

The following is very slow for long strings: std::string s = "long string"; K klist = DBVec::CreateList(KG , s.length()); for (int i=0; i
user443854
  • 7,096
  • 13
  • 48
  • 63