0

I have written a java problem to split the data from a single column into tabular form. How can I use the same code in Talend's Java Component.

The input File will have a column which will have the data in the below format: 1:Apple;2:Manogo;3:Cheery;4:Berry;

The code that I have written in Java is :

package com.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;

public class DateDemo {

       public static void main(String[] args) throws ParseException, IOException {
              File file =new File("File.csv");
              BufferedReader br = null;
              br = new BufferedReader(new FileReader(file));
              String line = "";
              while ((line = br.readLine()) != null){
                     System.out.println(line);
                     String[] csvDataArray= line.split(";");
                           for(int i=0;i<csvDataArray.length;i++)
                           {
                                  String[] csvData= csvDataArray[i].split(":");
                                  String id = csvData[0];
                                  String name = csvData[1];
                                  System.out.println("ID "+id+" Name "+name);
                           }
              }

       }

}

The output which I get from this code is below :

ID 1 Name Apple

ID 2 Name Mango

ID 3 Name Cherry

ID 4 Name Berry

How can I implement the same in Talend.

I assume we have to use the components below : tfileinput---main---tJava--main--tFileoutput

But if i am pasting the above code in Tjava, it is giving me errors, while it is running fine in eclipse.

How can i achieve this in Talend.

user3454116
  • 184
  • 1
  • 12

1 Answers1

0

The task you are describing looks like a standard normalization of your input data. Although using a tJava component will definitely be one way to do this (provided you tackle the conding problems) I would rather suggest to use one of Talends built-in components. Take a look at tNormalize.

tNormalize component

It lets you define the separation character to split the string and the input column containing the string to be split.

Marcus Rickert
  • 4,138
  • 3
  • 24
  • 29
  • Thanks @markus. I am able to split the data into different rows which is half my requirement. But I also wanted the data into two columns based on the colon. As of now I am getting seperate rows based on the semicolon ,but once I seperate the input into rows, i also want to split the news rows into two columns. How can i achive this. – user3454116 May 21 '16 at 01:42