Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aggregation of data in microsecond bars in kdb+

How can I use the xbar function to aggregate rows in a table in 10 microsecond bars. The table consists of the columns timestamp and val. For aggregating in millisecond bars instead I already know that I can simply use timestamp.datetime in the xbar query.

A possible result table should look as follows:

timestamp                 | val
--------------------------| ---
2015.12.02D12:19:44.434430| 2
2015.12.02D12:19:44.434440| 8
2015.12.02D12:19:44.434450| 5

Any help is appreciated.

like image 554
user1056903 Avatar asked Oct 19 '22 21:10

user1056903


1 Answers

The below should work:

d:([]t:asc .z.P+100*10?100;v:10?10)
select avg v by (10*1000) xbar t from d

Note that the output time column is still a 'timestamp' ("p") type, however the values are barred in microseconds.

I wrote the first xbar argument as (10*1000) for clarity. To change to 5 microseconds you can do (5*1000) etc.

like image 139
jgleeson Avatar answered Oct 21 '22 20:10

jgleeson