Search code examples
databasekdb

Mask some fields when loading hdb in kdb


If there are two instances: a1 and a2, and both connect to the same hdb. I would like a2 connect to the hdb but add some filter. For example, there is a table called elec.

I would like a2 starts with filtering some of the values. If I write codes and let a2 load it when starting, doesn't that load the information to memory? Is there any way I can load it like normal hdb when starting a2 instance?

Basically, the question is how to mask some fields in one table when loading hdb?


Solution

  • It is possible to prevent columns from being returned by select statements be manipulating the table definition in your HDB instance. The below example has a single date paritioned table. We update the definition to a flipped dictionary with only a subset of the columns defined. This however is reversible and will not update the meta of the table in your instance which will still show all columns.

    q)meta trade
    c   | t f a
    ----| -----
    date| d
    sym | s   p
    size| j
    px  | f
    side| s
    
    q)flip trade
    `sym`size`px`side!`trade
    
    
    q)`trade set flip `sym`size`px!`trade
    q)select from trade where date=2017.05.27
    date       sym  size px
    ------------------------------
    2017.05.27 APPl 9968 92.79204
    2017.05.27 APPl 9788 94.97189
    2017.05.27 APPl 9660 27.62907
    
    q)meta trade
    c   | t f a
    ----| -----
    date| d
    sym | s   p
    size| j
    px  | f
    side| s