/ jq, an implementation of q on the JVM / Warning first ever load will take up to 50 seconds. / Within this editor: / Press Control+Enter to run a line / Press Control+E to run the highlighted text / It supports most the simple mathematical operations 2+2 10%2 // Both against atoms and lists 1 2 3 - 100 200 10 100 * 1 2 3 where (0=til[1000] mod 5) or 0=til[1000] mod 5 / storing values a:13 b:til 10 a + based // Many of the types are supported .z.t .z.d ts:2019.01.13D12:22:11.1234 `minute$ts `second$ts // These behave as you would expect 2013.07.17+1 08:01 + 1 2 3 // Almost all casting and parsing `int$1.5 2.9 `$"hello world" // A subset of operations type `ppp`ooo l:20?20 l first l l 2 3 2 2 / and indexing / We can create dictionaries `a`b`c!1 2 3 / of various types `pp`oo`ii!(100 200; 0.1 0.2 0.3; "asda") type `pp`oo`ii!(100 200; 0.1 0.2 0.3; "asda") / and tables t:([] date:2030.01.01+0 1 2; sym:`pp`oo`ii; time:09:00+ 1 2 3; v:3?10) t / What you are seeing within the web version / is a javascript based JVM running the q application. / The full version can be downloaded from: / http://timestored.com/jq `a set 13; get "a" @[neg;1] a:*[;3];a 2 .[*;2 3] asc 3 1 2 null 3 0N 1 2 / Strings upper "test" lower "TEst" // Boolean logic 1100b and 1010b all 111b any 0001b -1^1.1 2.2 0n 4.4 0n 5.5 system "cd" \cd
/ ########## TimeStored Training Course - Getting Started ####### / http://www.timestored.com/kdb-training / type math expressions directly into kdb 10+3 900 - 88 13*2 90%20 / division is the percentage symbol / Expressions are evaluated right to left 100%10+10 / Defining a variable a:13 a b:10*9 b a+b c:a+b c / comments must be space then slash then comment / within a script there's another format / on new line then closed later b: 1 / comments b: 1 / whitespace doesn't matter in kdb / What objects exist on the server \v / variables \a / tables system "v" system "a" / can alter settings e.g. Precision and Console size \P \c \c 22 88 \l script.q / If the slash command isn't recognised as a kdb call / it's passed to the underlying OS, e.g. dos commands \cd \echo test system "cd" / See function list in timestored booklet \\ exit 0;
/ ########## TimeStored Training Course - Casting and Parsing ####### / http://www.timestored.com/kdb-training / ######## Casting ######## / The $ symbol is used to perform casting from one native / type to another in kdb. The right hand side contains our value, / The left hand specifies the type we want to cast to, / this can be specified in three ways: / 1. Type Symbol name / 2. Type char / 3. Type short number `int$7.3 "i"$7.3 6h$7.3 n:7.321 `long$n "j"$n 7h$n / casting rounds integers "j"$7.5 "j"$7.4 / depends on binary representation "j"$7.49999999999999999999999999999999 "e"$8 "f"$8 / When casting to some types the behaviour may not be intuitive / When casting to boolean, Zero/0 is false, everything else is true. `boolean$9 / anything non-zero is true `boolean$-9 `boolean$0 / #### Dates / Times / Earlier we saw `int$date returned the underlying value of the bytes. i.e. / Dates - number of days since 1st January 2000 / Times - number of milliseconds since midnight `int$2000.01.05 `int$00:30:59 / these can in fact be cast back to date/time etc. / where the integer number is the number of units of the smallest measure `date$4 `second$1859 `time$2 `minute$2 `second$2 `timestamp$2 `timespan$2 / #### Chars / Symbols #### `int$"A" / casting char to int returns ascii value `char$65 / reversible / kdb will attempt to convert almost anything, while rarely throwing an error `time$-1.4 / floats are rounded `time$"sad" / characters to time!? `time$`asd / gives an error / operations on date time types work on the underlying numeric values / types are automatically converted to the more complex type. 2013.07.17+1 2013.07.17+2 09:30:22 + 18 1b+13 2013.08.09D13:05:24.237584000 + 100 / ######## Parsing ######## / parsing from strings, use upper case letter "I"$"99" "J"$"99" "E"$"99.5" "F"$"99.5" / dates and times are the same format as expected. dayb:"2013.07.17" "D"$dayb; "D"$"2013-07-17"; / accepts hyphens aswell as dots in dates. "T"$"10:42:27.824" / if we tried the lowercase, it attempts to convert each character to a number instead. "i"$"99" "e"$"99.5" / any items which fail to parse return a null rather than fail. "J"$"99.4" "M"$"2013.03.14"