v 0.5 β
From qbie to qbist
TL;DR
Kdb+ is the world’s fastest timeseries database, and q is its native query language.
Q201 is for you if you have learned to write q and want to get good at it.
You probably learned q informally from workshop examples and colleagues. For many of us this is enough.
If you need more, q201 formalises, extends, and exercises your knowledge of the language.
You can also find here study partners and a chat room for q students.
Who does not need q201?
Maybe you.
Q is a domain-specific query language embedded in k4, (hereafter k)1 the language built into kdb+.
K is a blend of APL and Lisp, neither of which is widely used today. It is terse, elegant – and very different from the languages most coders learn.
Early users of kdb+ had to learn k to get anything done. Q was wrapped around k to get new users productive more quickly. With q you can get useful work done in kdb+ without mastering the language. Q has been successful, and KX no longer documents or supports k.
Q, q, q.
So that’s you: the qbie.
These days you can also handle kdb+ datasets using Python and SQL.
If all this is enough for your work – if you simply use q as a data pipeline – you don’t need q201. You’re fine.
Who needs q201?
But if you need
- to wring the most speed out of kdb+
- to maintain code written by qbists (skilled q coders)
then you need to become a qbist. The best way to become a qbist is to work with one.
Q201 aims to be the second-best way.
And here we are.
Still not sure?
The pairs of expressions below give different results. If you can explain why that is – or you just don’t care – you don’t need q201.
q)(+) prior til 4
0 1 3 5
q){x+y} prior til 4
0N 1 3 5
q)3 4 1 5 9?(3 4; 1 5 9)
0 1
2 3 4
q)3 4 1 5 9?(3 ;4 1 5 9)
'type
[0] 3 4 1 5 9?(3 ;4 1 5 9)
^
q201 is a work in progress.
Some pages are marked as drafts and contain FIXME
notes on work yet to be done.
Please send corrections, suggestions and extensions to sjt@5jt.com. (See Contribute for details.)
Acknowledgements
I have been blessed with suggestions and criticism from Brooke Allen, Erik Friis, Rian Ó Cuinnegáin, Rory Kemp, Nick Psaris, Dennis Shasha, Alex Unterrainer, and Arthur Whitney, for which I am deeply grateful.
Many of the good ideas are theirs; the mistakes are all mine.
I am grateful too to Konanki Raja Sekhar and Will Woodward, early users of the content.
Version
The examples were evaluated using kdb+ V4.1
Stephen Taylor
London, 2024
-
Both q and k are spelled in lower case. Both were designed and implemented by Arthur Whitney, a Canadian computer scientist whose shift key is always broken. K has seen several incarnations, and it is tempting to refer to them as ‘versions’. (Q is implemented in k4.) But no incarnation of k has been compatible with its predecessors, so perhaps one might think of them as a family of languages – except that Whitney insists: There is only one k!.
It seems there might be an ideal, perfect k language on which he is converging. We must leave him to work this out with Plato. You can see Whitney’s progress at shakti.com. ↩