Teneo Developers Community

Issue reading TSV files using ResourceHelper

Hi,

I am having a problem reading a TSV file using ResourceHelper method loadTSV.

I have a tab separated file that looks like this:

a b c
12 12 1231
1 2 3

I load this in via ResourceHelper the returned object shows a size of 2 (correct) but I cannot access any values as I iterate each row e.g. row.a, row.b etc. It returns a null value.

Can you take a look please or give me a pointer as to what I may be doing wrong?

Regards
Mark

Hi Mark,

the reason why you cannot acces the values using row.a, row.b etc is that the keys β€œa”, β€œb” and β€œc” are stored as GStrings in groovy. However, accessing values using row.a, row.b etc. is only possible if the keys are Strings.

In order to solve your problem, you can simply modify the ResourceHelper.groovy file by exchanging this line:

map << ["$key": vals[i++].trim()]

with this line:

map << [("$key".toString()): vals[i++].trim()]

This transforms the keys to strings before they are stored in the map and thus they will be accessible as usual via row.a, row.b etc.

Don’t forget to remove the original ResourceHelper.groovy from your solution and then add your modified version of it to the solution!

We may in the future consider changing the ResourceHelper.groovy file permanently towards using strings as keys and then update the version we provide for download on teneo.ai accordingly.

Best wishes,

Fabienne

3 Likes

Thanks Fabienne, changed this and now works for me. Thanks for the quick response!

1 Like