Record length and logging

How do I get the record length in the expression of ExtFilter? Also, is it possible to log the value of certain expressions. I tried length($in.0) == 55 but it did not work as expected. It would be nice to be able to log to see what value length($in.0) has for the various records.

Thanks
Navin

Dear Navin,

There isn’t a direct way to find out the size of a record in CTL. In case of some data types (e. g. map) it is not obvious, what length you need (number of keys, total size of values, size in bytes, size when it is saved in disk etc.).

But there are methods to calculate length of some data types. You can either use Java function DataRecord.getSizeSerialized() in the transformation or you can try to emulate the same functionality in CTL or calculate the size of record, when it is saved into the file.

I prepared for you an example. There is a generator which generates some fields of different data types. In the Reformat component there is an iteration over field index and for each field the length is calculated. Please note the calculation of length depends on the data type. E.g. length of byte and string is calculated by the length function (in case of string is multiplied by two because of UTF-16 internal encoding). Size of other field types is constant (in bytes): integer = 4 bytes, long = 8, boolean = 1, date = 8, decimal = 4 or 8 (according to precision) and number = 8.

In the second part of example there is used the Java function to calculate size of serialized record.

Third part of graph uses UniversalDataReader component which reads each record in one line and returns length of the line. This illustrates what is the size of record, if you want to save the record into file.

Please look at this example, I hope you can choose a method that would suit you.

Thank you for your insightful answer. I did not realise how ambiguous my question was. What I wanted was the count of all characters as they are written out to a string. E.g. “Navin,Khanna,40,10000.00” should count as 21 (excluded the commas) I think i can use the Java sample in my example.

Thanks
Navin