KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Parsing with fixed length

  • Parsing with fixed length

    Posted by ishasaxena on December 7, 2022 at 12:00 am

    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

    ishasaxena replied 8 months, 2 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • rocuinneagain

    Member
    December 8, 2022 at 12:00 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.

  • gyorokpeter-kx

    Member
    December 8, 2022 at 12:00 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.

Log in to reply.