Search code examples
kdb

Where is the attribute information stored for partitioned table in kdb


I have a partitioned table in kdb which is partitioned on data and parted on tick column.
Where is the attribute metadata that the table is parted on tick column being stored in kdb?

Example -

t:([] tick:10?`amzn`fb`goog; px:10?10.; vol:10?1000) / Create a table in memory
.Q.dpft[`:db;2023.10.01;`tick;`t] / Partitioned on date and parted on tick

Now loading the db in q session

\l db
meta t
c   | t f a
----| -----
date| d    
tick| s   p
px  | f    
vol | j

If I look at the .d file of the table it consists on only the column order.

get `:2023.10.01/t/.d
`tick`px`vol

Solution

  • You are right in that the attribute information is stored in the column/file and can be seen using a get:

    get `:2023.10.01/t/tick
    `p#`sym$`p#`amzn`amzn`fb`fb`fb`fb`fb`goog`goog`goog
    

    Under the covers it is represented by a single byte as per this example: https://code.kx.com/q/kb/serialization/#integer-vector

    q)-8!`p#1 2j
    0x010000001e00000007030200000001000000000000000200000000000000
    
    bytes       semantics
    0x01        little endian
    000000  
    1e000000    message length (30)
    07          type (long vector)
    03          attributes (00 – none, 01 – s, 02 – u, 03 – p, 04 – g)
    02000000    vector length (2)
    0100000000000000    first item, an 8 byte long (1)
    0200000000000000    second item, an 8 byte long (2)