KX Community

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

Home Forums kdb+ how to understand the code below

  • how to understand the code below

    Posted by chan_chenyanj on April 15, 2022 at 12:00 am

    suppose you have a table with several columns named col1 like `3Y`5Y and col2 like `3Y`4Y so they are vector of symbols and call table t

     

    how can i read the below two queries

     

    1. update {y,x} '[iasc each col1;col2] from t
    
    2. delete from t where 0< sum each `=/:(col1,`@[;0] each col2)
    chan_chenyanj replied 2 months ago 2 Members · 2 Replies
  • 2 Replies
  • leahs

    Member
    April 15, 2022 at 12:00 am

    Hello @chan_chenyanj,

    At first glance, ‘1’ seems erroneous. I suspect a rank error when you run ‘1’ with root cause ‘iasc each col1’.

    The ‘iasc‘ keyword accepts a list or a dictionary and col here is a simple symbol list and so there would be no need for ‘each’. ‘iasc’ returns the indexes needed to sort the list in ascending order.

    Remove ‘each’ and step through to see the output.

    Before stepping through ‘2’, is your intention to query original t, or query an updated table that you could assign to ‘1’ (currently would suspect an error returned for both cases)

    I can run the code next week and explain the logic further. Fellow contributors may be able to share in the meantime.

    Happy Coding.

  • leahs

    Member
    April 19, 2022 at 12:00 am

    Hello @chan_chenyanj,

    As we discussed previously regarding ‘1’, including ‘each’ here will return a rank error given that ‘iasc’ accepts a list as its argument and `3Y`5Y is a simple symbol list.

    To elaborate on ‘2’, I believe you want to query an updated table created after running ‘1’, i.e., assign ‘1’ (without each)

    ‘2’ logic is erroneous. `@ needs to be replaced with ‘@. To explain the logic, it is determining whether or not the new columns have a null symbol, and if it does, then delete from the table.

     

    Happy Coding,

    Leah

Log in to reply.