Search code examples
kdb

kdb - Simplifying a query with maps and lj


I have few tables already loaded into memory

//the real table is huge
st:([] s:`a`a`a`b`b`b;n:3 5 7 3 5 7; v:`U20`U30`U50`U22`U33`U44)

//step function
st1:`s#select first v by s,n from st

//mapping function 
f:{  (st1([] s:(),x 0;n:(),x 1))`v}

/Another table
t:([] s:`a`b`b;v:4 6 8)

//user input
MAP:([ KEY:`U20`U33`M40 ] VAL:200 330 440 )

Is there a way to simplify the following one? Here I am creating a temporary column KEY for lj and then deleting it

delete KEY from (update KEY:first each f each (s,'v) from t) lj MAP

Solution

  • If you can convert the user input (currently it's keyed table) to a dictionary

    MAP2:`U20`U33`M40!200 330 440 
    

    The new query with MAP2:

    update VAL:MAP2@f each (s,'v) from t
    

    Actually, the following is bit simpler and faster:

    update VAL:MAP2@f ( s;v) from t