kdb

Incompatible list lengths when passing a list of symbols into function parameter?


I have a function that filters on a master table as the below:

condSel:{[tabl;colNames;colValues]
    wc: {(in;x;enlist y)}.'flip(colNames;colValues);
    res: ?[tabl;wc;0b;()];
    res

I can apply this separately to filter on two columns within my master table:

res_fltr1: condSel[t;enlist `s; enlist `s1];
res_fltr2: condSel[t;enlist `name; enlist `$("P Willy";"D Reim")];

But it is only when I try to combine these two columns inside the filter function that I receive an incompatible list error that I am very unsure on how to fix:

res_fltr: condSel[t;`s`name;`s1`$("P Willy";"D Reim")];

What am I missing here? If I attempt this on columns s and p instead where I would pass one symbol for each column, then there are no issues.

res_fltr: condSel[t;`s`p;`s1`p1];

Dummy table below:

s  p  qty   name
------------------
s1 p1 300  F James
s1 p2 200  P Willy
s1 p3 400  P Willy
s1 p4 200  D Reim
s4 p5 100  M Oxhart
s1 p6 100  P Willy
...

Solution

  • This syntax is incorrect:

    q)`s1`$("P Willy";"D Reim")
    'type
      [0]  `s1`$("P Willy";"D Reim")
    

    You need to join them using ,:

    q)`s1,`$("P Willy";"D Reim")
    `s1`P Willy`D Reim