cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing with fixed length

ishaSaxena
New Contributor

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

2 ACCEPTED SOLUTIONS

gyorokpeter-kx
New Contributor III
New Contributor III

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.

View solution in original post

rocuinneagain
Contributor III
Contributor III

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. 

View solution in original post

2 REPLIES 2

gyorokpeter-kx
New Contributor III
New Contributor III

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.

rocuinneagain
Contributor III
Contributor III

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.