kdb

fills on empty sub lists in KDB


Consider a table containing a column a which is a list of lists as

q) show t: ([] a: ((1;2); (); (); (5;6); (); ()));
a  
---
1 2
() 
() 
5 6
() 
()

I'm having trouble filling the empty sublists () with the most recent non-empty list to get the expected output

a  
---
1 2
1 2
1 2
5 6
5 6
5 6

I tried

t:update a: 0N from t where 0=count'[a];
t:update a: fills a from t;

but I got

'nyi
  [4]  t:update a: fills a from t;

Solution

  • You can use a custom fill function and scan in this case. fills does not work well with nested lists.

    q)update a:{$[count y;y;x]}\[a] from t
    a
    ---
    1 2
    1 2
    1 2
    5 6
    5 6
    5 6