KX Community

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

Home Forums kdb+ insert into global table in peach

  • insert into global table in peach

    Posted by xiaocheng on September 26, 2021 at 12:00 am

    Suppose we have table tblAAPL, tblIBM already, can I insert data into each table by using peach to accelerate the process? If tables do not affect each other.

    for example:

    insert[; data] peach `tblAAPL`tblIBM

     

    I tested, got noupdate error.

    xiaocheng replied 1 month, 3 weeks ago 4 Members · 6 Replies
  • 6 Replies
  • rocuinneagain

    Member
    September 26, 2021 at 12:00 am

    No, it is not possible to update a global variable from any thread other the main thread.

    The ‘noupdate’ error is detailed on: https://code.kx.com/q/basics/errors/

    Full list of blocked operations within peach: https://code.kx.com/q/ref/each/#blocked-within-peach

     

     

  • sstantoncook

    Member
    September 27, 2021 at 12:00 am

    What is the use case that you want to insert the same data into two different tables?

    I can see the topic names resemble stocks but there is no filter on the data so would appear all records go into each.

    The only use case I can think of having the same schema and upserting to two tables is where you maintain two versions the same schema but one with keyed columns to maintain both the full trail and current “state”.

    E.g. all FX quotes in one table and the other keyed by Currency Pair and LP to display the current quoted depth.

    Cheers,

    Sam

  • darrenwsun

    Member
    October 7, 2021 at 12:00 am

    Is it the bottleneck that needs optimization? insert is quite cheap.

  • sstantoncook

    Member
    October 7, 2021 at 12:00 am

    The q insert is highly optimised, it can handle millions of rows a second per core.

    The insert must be performed in the main thread to ensure data consistency and sequencing. This is why it cannot by run with peach, even though in this example it is appending to different tables.

    What use case is there to insert identical data into two tables? There may be a more appropriate process architecture to manage these tables or mechanism to achieve the same result.

  • xiaocheng

    Member
    October 8, 2021 at 12:00 am

    Thanks. insert is a simple example here. Complex case might be, I need to apply sort rule to each table of tickers. Then, sort one by one is not efficient and tables will not affect each other, so peach can be helpful. I tried, but found cannot update the global tables in peach.

  • darrenwsun

    Member
    October 8, 2021 at 12:00 am

    If that’s what you really have to do, one way is to split those tables into multiple instances and use .z.pd (slave processes) for parallel computation. This adds to the complexity though so it’s not necessarily worth the cost.

Log in to reply.