Dynamic table name

Hi Gurus, 

Quick question: if one needs to generate a random variable name for a table and then serialise it, how would you go about it? 

For example:

tabName: 1?`8

tabName set … (here I generate the actual table and assign it to the variable tabName) 

Surely, two steps above make no sense, 1st step generates random name, 2nd step takes “tabName” as the actual name and then assigns some data to it. So the 1st step is ‘lost’. 

But then, how would one use this name (randomly generated) to serialise and store it on the disk? 

`/db/tabName set tabName

Thank you for your help, 

Regards,

VA. 

Assign and set in one line. And you can use .Q.dd to create the path with your random table name, then set

flat
q).Q.dd[:/var/tmp;t] set (t:1?8) set (10?10;10?10)
:/var/tmp/mfmfnmom q).Q.dd[:/var/tmp;t] set (t:1?8) set ([]10?10;10?10) :/var/tmp/eobdbgdi

splayed
q).Q.dd[:/var/tmp;t,] set (t:1?8) set ([]10?10;10?10) :/var/tmp/pgdjicki/
q).Q.dd[:/var/tmp;t,] set (t:1?8) set ([]10?10;10?10) :/var/tmp/cpejdmlm/

(or remove the set to the t variable, if all you are looking to do is to write to disk.

May I ask why you are doing this? Something I have never seen needed.(at least not completely random table names)..

Sean

Thank you Sean, this is great. 

The reasons for doing this: 

I have a huge file “A” and I am building table “B” from this file. The problem is that I run into memory problems when building “B” table. So what I want to do is to build several smaller tables out of file “A”, then merge these small tables into one table “C” and then merge the final table “C” with an empty splayed table.

Quick question while we are on this topic: once I generate all the tables I need, how do I get these tables’ names to merge them? So say, the tables are located in `:/var/tmp/

`:/var/tmp/

How do I get the contains (tables) of tmp folder and apply these names in a function that will merge all those tables one by one? Simple union join works perfectly: (uj/) (t1; t2; t3)

This is probably not the best and most sophisticated way to work the problem, but this is the only way I know of for now. 

Regards, 

VA. 

Why would you do this in this way?

Could you just append the chunks directly to your final table with upsert?

WBR, Andrey Kozyrev.

???, 21 ??? 2017 ?., 7:02:02 UTC+3 ??? VA ???:

Thank you Sean, this is great. 

The reasons for doing this: 

I have a huge file “A” and I am building table “B” from this file. The problem is that I run into memory problems when building “B” table. So what I want to do is to build several smaller tables out of file “A”, then merge these small tables into one table “C” and then merge the final table “C” with an empty splayed table.

Quick question while we are on this topic: once I generate all the tables I need, how do I get these tables’ names to merge them? So say, the tables are located in `:/var/tmp/

`:/var/tmp/

How do I get the contains (tables) of tmp folder and apply these names in a function that will merge all those tables one by one? Simple union join works perfectly: (uj/) (t1; t2; t3)

This is probably not the best and most sophisticated way to work the problem, but this is the only way I know of for now. 

Regards, 

VA. 

if uj does work for you then to get the contents of a directory just use ‘key’
key`:/var/tmp - this will tell you the contents

However I think you should perhaps have a look at .Q.fs[n] - it loads in chunks and should avoid most of the memory issues you are having with the loading.
http://code.kx.com/wiki/Cookbook/LoadingFromLargeFiles

HTH,
Sean