Nefrasky
Nefrasky

Reputation: 69

How to parse an unconventional file with Talend?

I have a file shape like this :

enter image description here

How can I parse a file like this with Talend Open Studio ?

Here's what I tried :

enter image description here

In the tJavaRow, the input is the whole file in a single row. I split it and parse it manually. But I can't figure out how to create an output row for each OBJ in the file.

Is this the "Right" way of doing it ? Or is there a specific component for this type of files ?

Upvotes: 1

Views: 393

Answers (1)

p1234
p1234

Reputation: 529

But I can't figure out how to create an output row for each OBJ in the file

You can do this by using the tJavaFlex component:

  1. Put your raw content in the globalMap by connecting it to tFlowToIterate
  2. Put your split-and-parse logic in the "Start Code" part of tJavaFlex, using the contents you made available in step 1
  3. Start a loop in the "Start Code" part of tJavaFlex (e.g. for each object)
  4. Define your output schema in tJavaFlex
  5. In the "Main Code" part of tJavaFlex, map your parsed object to the columns of your output row
  6. Dont forget to close your loop in the "End Code" part of tJavaFlex

I layed out a quick example, with no parsing logic. But since you already got this down, I think it should be sufficient: demo flow

Start Code

String[] lines = ((String)globalMap.get("row1.content")).split("\r\n");
for(String line : lines) { // starts the "generating" loop

Main Code

    row2.key = line; // uses the "generating" loop

End Code

} // closes the "generating" loop

Upvotes: 3

Related Questions