KDB+ Tutorial
KDB+ Architecture
Q Programming Language
Q Advanced Topics
KDB+ Useful Resources
Selected Reading
KDB+ Architecture
Q Programming Language
- Q - Message Handler (.Z Library)
- Q - Inter-Process Communication
- Q Language - Queries
- Q Language - Built-in Functions
- Q Language - Functions
- Q Language - Joins
- Q Language - Verb & Adverbs
- Q Language - Table
- Q Language - Dictionaries
- Q Language - Indexing
- Q Language - Lists
- Q Language - Temporal Data
- Q Language - Type Casting
- Q Programming Language
Q Advanced Topics
- Q Language - Maintenance Functions
- Q Language - Tables on Disk
- Q Language - Table Arithmetic
- Q Language - Functional Queries
- Q Language - Attributes
KDB+ Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Q Language - Verb & Adverbs
Q Language - Verb & Adverbs
Kdb+ has nouns, verbs, and adverbs. All data objects and functions are nouns. Verbs enhance the readabipty by reducing the number of square brackets and parentheses in expressions. Adverbs modify dyadic (2 arguments) functions and verbs to produce new, related verbs. The functions produced by adverbs are called derived functions or derived verbs.
Each
The adverb each, denoted by ( ` ), modifies dyadic functions and verbs to apply to the items of psts instead of the psts themselves. Take a look at the following example −
q)1, (2 3 5) / Join 1 2 3 5 q)1, ( 2 3 4) / Join each 1 2 1 3 1 4
There is a form of Each for monadic functions that uses the keyword “each”. For example,
q)reverse ( 1 2 3; "abc") /Reverse a b c 1 2 3 q)each [reverse] (1 2 3; "abc") /Reverse-Each 3 2 1 c b a q) [reverse] ( 1 2 3; "abc") 3 2 1 c b a
Each-Left and Each-Right
There are two variants of Each for dyadic functions called Each-Left (:) and Each-Right (/:). The following example explains how to use them.
q)x: 9 18 27 36 q)y:10 20 30 40 q)x,y / join 9 18 27 36 10 20 30 40 q)x, y / each 9 10 18 20 27 30 36 40 q)x: 9 18 27 36 q)y:10 20 30 40 q)x,y / join 9 18 27 36 10 20 30 40 q)x, y / each, will return a pst of pairs 9 10 18 20 27 30 36 40 q)x, :y / each left, returns a pst of each element / from x with all of y 9 10 20 30 40 18 10 20 30 40 27 10 20 30 40 36 10 20 30 40 q)x,/:y / each right, returns a pst of all the x with / each element of y 9 18 27 36 10 9 18 27 36 20 9 18 27 36 30 9 18 27 36 40 q)1 _x / drop the first element 18 27 36 q)-2_y / drop the last two element 10 20 q) / Combine each left and each right to be a / cross-product (cartesian product) q)x,/::y 9 10 9 20 9 30 9 40 18 10 18 20 18 30 18 40 27 10 27 20 27 30 27 40 36 10 36 20 36 30 36 40Advertisements