cancel
Showing results for 
Search instead for 
Did you mean: 

Amend Entire Works in memory but not with a handle?

jattwick
New Contributor II

I've noticed some weird behaviour with amend entire using lists of lists. The behaviour is different depending on whether on I use a file handle or pass the list directly to the function. Code to recreate is pasted below:

 

weirdPartition:(1 2 3f;();enlist 1 2 3);
file:`:./tester/weirdPartition;
file set weirdPartition;
addToWeirdPartition:(1 2 3f;4 5 6f);

// amend at?

// handle doesn't work? type error?
.[file;();,;addToWeirdPartition]
// in memory works?
.[get file;();,;addToWeirdPartition]

 

Anyone explain why it does not work with a handle?

2 REPLIES 2

cillianreilly
New Contributor III

I think this is due to the constraints specified here: https://code.kx.com/q/ref/amend/#on-disk, in particular that only vectors of types 1-19 can be updated directly on disk. Given that weirdPartition has type 0, it can't be updated on disk, but has no such constraints in memory.

Note: Personally unclear on whether the wording on the above link ("Certain vectors (types 1-19) can be updated directly on disk without the need to fully rewrite the file. ") means it can't be done, or it can be done but that the entire file must be rewritten, and there is another issue at play here. I'm leaning towards the former, and that modifications must be done in memory first before writing.

The weird thing for me is we have a process that writes in this fashion, running several times a day. In some cases, it fails (which makes sense given the explanation you have given), but it does work in some cases as well. might lean towards just re-architecting the datatypes for this table.