2022.12.07 01:20 PM - edited 2022.12.07 01:21 PM
There is a length error in loading fixed width error kdb 3.3 -
I am trying to load a text file of 17673 records. Each record is of 80 bytes with first 14 alphanumeric and remaining spaces. (here in below record spaces might not be shown correctly,but I did count each all are of 80 size.)
"1117XXABCDEFGH "
"1221YYABCDEFGH "
"1337ZZABCDEFGH "
"1447AAABCDEFGH "
This was working fine , but all of a sudden we have started seeing length error in loading the file using the below syntax. There are no special characters in the file. what could be the reason for seeing this issue?
("SSSSS";3 3 2 2 4)0: ` :file1.txt
'length
2022.12.08 02:22 AM
The 0: operator cannot handle filler between records. You either have to explicitly include the spaces as a field:
("SSSSS ";3 3 2 2 4 66)0:`:file1.txt
or find another way to get rid of the spaces.
2022.12.08 02:29 AM - edited 2022.12.08 02:35 AM
Try this to confirm the file is valid:
//Bytes per record
q)sum 3 3 2 2 4
14
//Bytes in file
q)hcount `:file1.txt
??
//Confirm bytes in file has no remainder if divided by bytes in record
q)0~hcount[`:file1.txt] mod sum 3 3 2 2 4
??
If last line returns 0b
then your file is not a valid size for those fixed length messages.
You can see quickly at the end of the file if the last record looks valid.
//Inspect the last records in the file to see visually if records look correct
q)-2#(sum 3 3 2 2 4) cut `char$read1
The issue could start anywhere in the file so you may need to do further investigation if it is still not obvious after checking the above.
2022.12.08 02:22 AM
The 0: operator cannot handle filler between records. You either have to explicitly include the spaces as a field:
("SSSSS ";3 3 2 2 4 66)0:`:file1.txt
or find another way to get rid of the spaces.
2022.12.08 02:29 AM - edited 2022.12.08 02:35 AM
Try this to confirm the file is valid:
//Bytes per record
q)sum 3 3 2 2 4
14
//Bytes in file
q)hcount `:file1.txt
??
//Confirm bytes in file has no remainder if divided by bytes in record
q)0~hcount[`:file1.txt] mod sum 3 3 2 2 4
??
If last line returns 0b
then your file is not a valid size for those fixed length messages.
You can see quickly at the end of the file if the last record looks valid.
//Inspect the last records in the file to see visually if records look correct
q)-2#(sum 3 3 2 2 4) cut `char$read1
The issue could start anywhere in the file so you may need to do further investigation if it is still not obvious after checking the above.
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.