2

I am extracting two columns using textractjson and passing it to a tmap component where I am concatenating both of the columns as single one.

Also, I want a comma at the end of each row except the last row.

I am not sure how to do this.

Example:

There are two columns in tmap as input:

  1. FirstName
  2. LastName

In output, I have concatenated them to:

FirstName+LastName+","

The problem is I dont want the comma in the last row.

Antti29
  • 2,953
  • 12
  • 34
  • 36

3 Answers3

1

This depends on your job layout and input structure.

You seem to use tExtractJSON, which could mean you get the data from a REST call or out of a database.

Since there is no fixed row amount because of the JSON data structure, you wouldn't be able to use ((Integer)globalMap.get("tFileInputDelimited_1_NB_LINE")). Again, since we don't know your job layout, this depends on it.

If this is not the case, I would count the rows in a tJavaRow component first and then add a second tJavaRow where I'd concat the strings (wouldn't do that in the tMap), but omit the last comma. I'd be able to find the last row with the count I did first. This depends on your Java skills.

tobi6
  • 8,033
  • 6
  • 26
  • 41
1

You may also concatenate all the rows in a global variable using a tJavaRow, with a comma at the end for each row.
Then, start a new subjob (onSubjobOk) then using a tJava, remove the last character (so the last comma).
Pretty simple, don't have to know how many rows from the input flow but supposing you want the result as a single string (here contained in a global variable).

TRF
  • 791
  • 4
  • 9
1

I might be wrong also. Basically concatenate FirstName and LastName , Create record number column using Numeric.Sequence() function and use one more context variable and store the same sequence number here(it might store last value) also in tJavaRow component.

output_row.name = input_row.FirstName+""+input_row.LastName+","+;
output_row.record_number = Numeric.sequence("recNo", 1, 1);
context.lastNumber = Numeric.sequence("recNo", 1, 1);

create a method in custom java routine.

public static string main _nameChange(String name,Integer record_number){
if(context.lastNumber == record_number){
name = name.substring(0,name.length()-1);
return name;
}
else{
return name;
}
}

Now call _nameChange method within tmap component. Now you can trim the last row's last character.
Ror reference check this

Murugan Perumal
  • 975
  • 5
  • 15