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
1 answer

How to build a parse-tree of projections?

I want to save somehow a parse-tree into a text format file, than bring it back to q. But a parse-tree could possibly contains projections, say +[;1]2. How should I process these file trees and correctly save/load it? I've got errors trying to work…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Could not evaluate manually created equial ~ parse tree

How could it be an equality of manually created parse tree and the result of parse operation: q)t:([]date:.z.d+til 5;ccy:5#`EUR`CAN`AUS;fx:5?(1.0 0.1)) q)@[;`date;1+]t date ccy fx ------------------ 2020.11.01 EUR 0.1 2020.11.02 CAN…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Select distinct for all columns from keyed table

It seems we can not get distinct values from a keyed table in the same way as for unkeyed: t:([a:1 2]b:3 4) ?[t;();0b;()] // keyed table ?[0!t;();1b;()] // unkeyed table ?[t;();1b;()] // err 'type Why do we have this error here?
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Multiple variable assignment in q

This code looks like multiple variable assignment: d:`a`b`c!1 2 3 d[`a`b]:10 20 Why is it working this way? And why it is not the same as (a;b):10 20 (which doesn't work)? I suppose the 2nd line will make only temporary assignment - do not actually…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
2 answers

Select a table from the inside of external select

I've seen a technique of use an update (mainly for side-effect of adding a new column, I guess) in a way of: update someFun each t from t. Is it good or bad practice to use such technique? Some experiments: t1:([]a:1 2); t2:([]a:1 2;b:30 40); update…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

NULLs in q and in k.h

I've found different values for h NULLs between k.h and q: q)0x00 vs 0W 0x7fffffffffffffff q)0x00 vs 0N 0x8000000000000000 q)0x00 vs 0Ni 0x80000000 q)0x00 vs 0Wi 0x7fffffff q)0x00 vs 0Wh 0x7fff q)0x00 vs 0Nh 0x8000 In q it all looks familiar, but…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
2 answers

Select when one of filter-column may not exists

Suppose a situation when it is not known if a filter column exists. t:([]a:`s1`s2`s3; c:1 2 3); select c from t where null t[`a] select c from t where null t[`b] 'length (where null t[`a])~where null t[`b] 1b It column a exists, then the select is…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

What is the meaning of `s attribute on a table?

In the Abridged Q Language Manual Arthur mentioned: `s#table marks the table to use binary search and marks first column sorted And if we look into 3.6 version: N:1000000; t1:t2:([]n:til N; m:N?`6); t1:update `p#n from t1; t2:`s#t2; (meta t1)[`n]`a…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Parallel execution: blocking receive, deferred synchronous

I've asked a question about errors that happened while parallel sync and async calls. And answer shed light on an even bigger questions: Does blocking receive construct replaces .z.ps/.z.pg calls? If there exists deferred synchronous (used in…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

On parallel execution - which side reports about an error?

When using different methods (sync/async) to callback a caller process I'm getting an error on different sides: $ q -p 1234 │$ q │q)h:hopen`::1234; │q)neg[h]({.z.w x};42) q)'type │ │q)neg[h]({neg[.z.w]…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Validate if a keyed table have unique keys

How to check if a table have unique keys? For one key-column it works: t:([k1:1 2 3]d:10 20 30); @[{update `u#k1 from t};`;{"Err: ",x}] But how to do the same for multiple key columns? t:([k1:1 2 2; k2:`a`b`b]d:10 20 30)
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Applying dictionary to dictionary

Recently I've found a technique of applying dict to dict. It is something like this: (3 4 5!6 7 8)[(`a`b)!(2 3)] ~ (`a`b!0N 6) or even this, which looks more natural for reading from left to right: (@[;(`a`b)!(2 3)](3 4 5!6 7 8)) ~ (`a`b!0N 6) Can…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Limits of string transformations in q, stars in TOK

I'm trying to convert int values to minutes, and in some cases it gives me stars * in the result: string "U"$"99:59" / "99:59" string "U"$"100:00" / "**:00" What are the rules for this stars to appear? Update for seconds: string "V"$"1000" /…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

About xkey implementation

What is the difference between a functional apply approach .[0!y;();xcols x], seen in xkey: xkey k){(#x)!.[0!y;();xcols x]} and a simple function calling: x xcols 0!y. Why is it the function apply preferred in xkey? And a second question about a…
egor7
  • 4,678
  • 7
  • 31
  • 55
0
votes
1 answer

Get additional column using functional select

How to get an additional column of type string using ?? I tried this: t:([]c1:`a`b`c;c2:1 2 3) ?[t;();0b;`c1`c2`c3!(`c1;`c2;10)] / ok ?[t;();0b;`c1`c2`c3!(`c1;`c2;enlist(`abc))] / ok ?[t;();0b;`c1`c2`c3!(`c1;`c2;"10")] /…
egor7
  • 4,678
  • 7
  • 31
  • 55