0

I have two csv files employee.csv and loan.csv.

In employee.csv I have four columns i.e. empid(Integer),name(String),age(Integer),education(String).

In loan.csv I have three columns i.e. loan(Double),balance(Double),empid(Integer).

Now, I want to merge these two csv files into a single csv file by empid column.So in the result.csv file the columns should be,

  • empid(Integer),
  • name(String),
  • age(Integer),
  • education(String),
  • loan(Double),
  • balance(Double).

Also I have to achieve this only by using kettle api program in Java. Can anyone please help me?

1 Answer 1

1

First of all, you need to create a kettle transformation as below:

  1. Take two "CSV Input Step", one for employee.csv and another for loan.csv
  2. Hop the input to the "Stream Lookup" step and lookup using the "emplid"
  3. Final step : Take a Text file output to generate a csv file output. enter image description here

I have placed the ktr code in here.

Secondly, if you want to execute this transformation using Java, i suggest you read this blog. I have explained how to execute a .ktr/.kjb file using Java.


Extra points:

If its required that the names of the csv files need to be passed as a parameter from the Java code, you can do that by adding the below code:

  trans.setParameterValue(parameterName, parameterValue);

where parameterName is the some variable name and parameterValue is the name of the file or the location.

I have already taken the files names as the parameter in the kettle code i have shared.

Hope it helps :)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Rishu for your quick reply.I appreciate your help.I am able to execute existing .ktr file with java code. But my requirement is to create .ktr file from above two .csv files using java code (not spoon). Can you please help me for this, if possible can you please share java code for the same so that i can create .ktr file using java. I want to create .ktr file using java code from two or more .csv files.
@Rishu, I have looked at your code in github. My problem is that I can't find org.pentaho.di.core.KettleEnvironment class. I've downloaded all required jars but it's not there. In which jar it is supposed to be?
@Lyd KettleEnviornment class will be available in the core kettle jar. Not sure what exactly you have imported. I have used maven to import the jars...try checking link... hope it might help !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.