Questions tagged [k]

k is an array processing language used in the kdb+ database. Do not use this tag for general kdb questions - only for questions pertaining to code in the k language.

K is an array processing language developed by Kx Systems. It is the foundation of the database used in financial products. K draws inspiration from APL and Scheme.

78 questions
0
votes
3 answers

Indexing dictionary in depth, two cases

When indexing dictionary in depth I've found different results in the same (as I think) constructions: q)d:`a`b!(1 2 3;4 5 6) q)d[`a`b;0] 1 4 q)d[`a`b]0 1 2 3 Why is this happening? How q understands and distinguishes two different cases? Before…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
2 answers

Restrict table columns, preserving keys

I've found in "Q Tips" a technique to preserve keys in a table. This is useful for restriction columns in the right table in lj for example, without re-applying a key. Using each: q)show t:(`c1`c2!1 2;`c1`c2!3 4)!(`c3`c4`c5!30 40 50;`c3`c4`c5!31 41…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
2 answers

Upsert list of lists to the table

Let's see the definition of upsert: q)upsert .[;();,;] So it is just an Amend Entire: .[d;();v;y] <=> v[d;y] q).[1 2; (); ,; 3 4 5] 1 2 3 4 5 It looks like join , under the hood. But applying the same approach to adding some rows to a table…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Is creating a file-tree a built-in feature of q?

I've seen in .Q sources (q.k) that applying a dir-symbol to empty symbol (or to its sub-dir symbol) creates a full folders-tree, try this: `:dir1 ` Is this behavior documented somewhere? Or is this a feature for internal use only and is subject to…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Create single-row table by enlisting only one column

In a wp/rt-tick I saw a technique to create a single-row table by giving enlisted element to only one column: /single-row update for the trade table (`upd; `trade; ([]time:enlist 0D10:30:59.5; / <- enlist is only here sym:`IBM.N; …
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Table cols definition

There are a bunch of tricks used in kdb+ to work with keyed/splayed/partitioned and simple tables. I see lots of .Q functions which work as a facade for these varieties. One of them is cols. Could you help me please with one of the cases - what the…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Join usage scenarios

The official docs covers only the basic usage of join. But one could see how the left join lj is implemented: q)lj k){.Q.ft[,\:[;y];x]} q).Q.ft k){$[$[99h=@t:v y;98h=@. t;0];[n:#+!y;n!x 0!y];x y]} and so one could find another use case (dict,keyed…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Handling single-character strings - in a function or in its caller? ssr()

What is the common way to work with strings in q, in a way, who is responsible for handling a single-character string: function itself or a user who runs it? Ex: $ q KDB+ 3.6 2019.04.02 Copyright (C) 1993-2019 Kx Systems m32 q)ssr["bar";"r";"z"]…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

0D type and n?0D randoms

In A brief introduction to q and kdb+ there are several places with creation of time records with code like 0D00:01. And even random time generation technique using syntax: n?0D0 fcn?0D00:00:20 I found 0D mentioned only in q4m3 2.5.2 Time Types as…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Enum does not hold its keys, only a ref to keys instead

According to documentation at https://code.kx.com/q/ref/enumerate/ Enumerate Syntax: x$y, $[x;y] Where x and y are lists I suppose a correct way to create enum would be through giving lists to the $: q)e:`a`b`c$`b`a`c`c`a`b 'length [0] …
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Prefix notation for view definition

I thought that (almost) any q function could be called with prefix and infix notation interchangeably. But then I've tried: $ q KDB+ 3.6 2019.04.02 Copyright (C) 1993-2019 Kx Systems q)a:10 q)b::a q)a:11 q)b 11 q)view `b ,"a" looks good, but…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Expressions/operator precedence in Amend At and in function parameters

I always thought that in q and in k all expressions divided ; evaluated left-to-right and operator precedence inside is right-to-left. But then I tried to apply this principle to Ament At operator parameters. Confusingly it seems working in the…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Variable scope propagation in k

I've seen a variable scope propagation to the inner function in previous versions of k. See eval: {[t;c]{x*t+y}/c} in http://www.math.bas.bg/bantchev/place/k.html But if I try to do the same in modern k, I get an error: KDB+ 3.6 2018.05.17 Copyright…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
2 answers

Converge (fixed point) syntax difference in q and k

We should use square brackets when flattering all levels in list: q)b:(1 2;(3 4;5 6);7;8) q)raze/[b] / flatten all levels 1 2 3 4 5 6 7 8 q)raze/b '/ [0] raze/b But why one forced to use raze/[b] for Converge syntax instead of…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
2 answers

Remove extra duplicate entries in unkeyed table

I have the following table below and would like to delete all rows that are duplicates. I have created a column dup which counts the number of duplicates. delete from table where dup>1 would delete all entries of the duplicate and I would still like…