Skip to content
Advertisement

using tfilelist or tfiledelimited how can i iterate through a list of columnA, column B combination and store in tjava to use for tdbinput

I have a talend job that i am trying to read the columns from the csv file sequentially row by row for each combination (if possible trying to collect unique combination) of COLUMN A & COLUMN B to get the values and store in tjava (context variables to reuse and query the tdbinput)

CSV in the below format: enter image description here

OPTION 1: My job design looks like this: tfilelist-Iterate–>tjava –>tdbinput

Tjava:

```
 `int n = 600; // The line number
      int i=0;
      String line="";
      int linenumber=0;
```

`try(BufferedReader br = new BufferedReader(new FileReader((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))))`
`{`

`while ((line = br.readLine()) != null && linenumber< n )`  
`{`
`if(iteration == 0)`
`{`
`iteration++;`  
`continue;`
`}`
`String[] tokens = line.split(",");`

```
   for(String token : tokens)
                {
                    //Print all tokens
                    System.out.println(token);
                }
```

`context.columnA=tokens[0];`
`context.columnB=tokens[1];`

```
     linenumber++; 
 }
```

```
```

When i try to use the context.columnA in the other component tdbinput it will has the last overwritten value and not the iterated value for each row sequence

tdinput: select * from test where testcol='”+context.columnA+”‘; RESULT IS NULL because context.columnA value is empty from tjava

OPTION 2:I tried using : tfileinputdelimited–main–>tjavarow

tjavarow:

context.columnA = input_row.columnA ;
context.columnB= input_row.columnB;

but this approach doesnt help me to directly pass the inputs into tdbinput(to query the database using select)

So i would like to know if there is a way to iterate from tfileinputdelimited—iterate–>tjava??? but unable to store the schema results between the component.

Updated job design for approach2: enter image description here

Anyone please advise a way to perform either using java code to handle it or adjust the talend components to achieve the desired result

Advertisement

Answer

try using your second approch :

tfileinputdelimited ->tJavaRow-main1->tFlowtoIterate->tdbInput

You can use the global Variable in tdbInput as below ((String)globalMap.get("main1.lot"))

Advertisement