Search code examples
kdb

KDB - Clearing out functions, variables, tables from server without exiting or restarting service


I'm currently setting up a server and successfully passing functions and test data to that server.

Is there an eloquent way to clear out all the functions, variables, tables, etc.? Since we are running KDB in a Docker container and accessing it via IP address, I prefer not to have to restart the q session on the server, but rather assign many/all values and functions to :: or null.

At present I'm assuming I have to reassign each function/variable/table to :: or similar to achieve this. It isn't a big issue but I expect to have numerous functions.

\p 5042
h:hopen `:XXX.XXX.XX.XX:5042
h "sq:{x*x}"   //send sample function sq to server
h "sq: ::" //assign function sq to nothing (repeat for all variables/functions/tables etc)
hclose h

//check the IP address list of functions to confirm deletion http://XXX.XXX.XX.XX:5042/?\f

Solution

  • Would you be able to give us a bit more information as to why you want to clear out everything (and in particular, why do you want to set functions to null)?

    Otherwise, you can do a few things. You can do a delete statement on a namespace to delete everything in it. To do delete all tables/variables/functions in the global namespace, you can do the following.

    q)a: 1
    q)b: 1 2 3
    q)f: {1 + x}
    q)value `.
    a| 1
    b| 1 2 3
    f| {1 + x}
    q)delete from `.
    `.
    q)value `.
    q)f
    'f
      [0]  f
           ^
    q)
    

    If you want to null them rather than delete them, you could use the system commands a, f and v to get lists of all the tables (a), functions (f) and varialbes (v) in the global (or other) name space, and then use set to set them all to null.

    q)f: {1+x}
    q)g: {2*x}
    q)(system"f")set'(::)
    `f`g
    q)f
    q)g
    q)
    

    Is this roughly what you were looking for?

    (One obvious problem with this is that you might end up deleting other peoples variables.)