KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Unpack nested column in table Re: Unpack nested column in table

  • darrenwsun

    Member
    August 23, 2022 at 12:00 am

    A generalized solution that doesn’t use hardcoded column names (provided as input) or assume the the cells in the nested column having the same length (padded with null for those with shorter length).

     

    unpack:{[t;c] maxLen:max count each t[c]; 
                  newCols:`$string[c] ,/: string 1+til maxLen; // concatenate the parts other than the specified column, with the unpacked parts 
                 //(x;::;y) is the parsed form of x[;y] 
                  ![t; (); 0b; enlist c] ,' ?[t; (); 0b; newCols!{(x;::;y)}'[c;til maxLen]] 
    }