'Is there a difference in performance between set/save when saving columns to tables?
I have a small utility that checks for new columns for an intraday hdb and adds new columns. At the moment I am using :
.[set;(pth;?[data;();();cls]);{[p;e] .log.error[.z.h;"Failed to save to path [",string[p],"] with error :",e]}[pth;]]
where path is :
`:path_to_hdb/2022.03.31/table01/newDummyThree
and
?[data;();();cls] // just an exec statement
Would it make any difference to use save
instead:
.[save;(pth;?[data;();();cls]);{[p;e] .log.error[.z.h;"Failed to save to path [",string[p],"] with error :",e]}[pth;]]
Solution 1:[1]
Yes. If you are adding entire columns to a table then you might want to store it splayed, i.e. as a directory of column files rather than as a single table file. This means using set
rather than save
.
https://code.kx.com/q/kb/splayed-tables/
But test actual example updates.
Solution 2:[2]
As mentioned in the documentation for save:
Use set instead to save
- a variable to a file of a different name
- local data
So set
has the advantage of not requiring a global and you can name the file a different name to the name of your in-memory global variable.
There is no difference in how they serialise/write the data. In fact, save
uses set
under the covers anyway:
q)save
k){$[1=#p:`\:*|`\:x:-1!x;set[x;. *p]; x 0:.h.tx[p 1]@.*p]}'
By the way - you can't use save
in the way that you've suggested in your post. save
takes a symbol as input and this symbol is the symbol name of your global variable containing the data you want to write.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | SJT |
Solution 2 | terrylynch |