• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » How to transmit an Object to a childjob ?

#1 2008-12-18 11:19:08

jyaime
Member
Registered: 2008-10-14
Posts: 22

How to transmit an Object to a childjob ?

Hi,

I've created two jobs, and I need to transmit an Object "ArrayList" to the childjob.
So I put my array list in the context : context.put(myArrayList);
Then, I call the childjob with a component tRunJob, with "Transmit whole context" checked. So it should transmit my list to the child's context.

But when I execute that, my array list is cast in a String (so there is a ClassCastException), because method "runJob" of each job only accepts String parameter.

So it  seems to be impossible to transmit something else than a String.

Do you have a solution ?
Thanks

Best regards,
Jean-Marie

Offline

#2 2008-12-19 04:04:04

shong
Talend team
Registered: 2007-08-29
Posts: 10309
Website

Re: How to transmit an Object to a childjob ?

Hello

But when I execute that, my array list is cast in a String (so there is a ClassCastException), because method "runJob" of each job only accepts String parameter.

yes, the Array have been transmit as a String (for example: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), so we can get the values from this String and set them into a new Array in child job.(see my screenshot)

Best


Uploaded Images


Email:shong@talend.com
Choose Talend, Enjoy Talend!
New & Event: Talend Help Center
Talend-->the leader of open source data management and application integration solutions!

Offline

#3 2008-12-19 23:17:33

Volker Brehm
Member
Registered: 2007-04-03
Posts: 1139
Website

Re: How to transmit an Object to a childjob ?

Hi Jean-Marie,

I think you are right. Actual the transfer is based on simple strings. I took a closer look on the code but it is some month ago. But if I remember right all transfer is based on a string. Your data is not casted, th toString()-function is used. Later in the subJob the string is parsed. This is an additional (and not necessary) overhead, error-prone and limited to simple types.

But a change to this functionality would need a greater change in the overall class design and the components.

I tried another solution with the following code. In this example i take a list of values (1,2,3,4,5) each in one row into a list and try to transfer the data into a sub job.

dataInput -> tJavaFlex -> tRunJob

mainJob:
tJavaFlex

Code:

//start code
java.util.ArrayList dataList= new java.util.ArrayList();
ByteArrayOutputStream baos= new ByteArrayOutputStream();
ObjectOutputStream oos= new ObjectOutputStream(baos);

// main code
dataList.add(row2.testData);
row3.testData2= dataList;
oos.writeObject(dataList);
oos.flush();
row3.testData2= baos.toString();

//end code
oos.close();

subJob:
tJavaRow

Code:

ByteArrayInputStream bais = new ByteArrayInputStream(((String)input_row.data).getBytes());
ObjectInputStream ois = new ObjectInputStream(bais);
output_row.data= (String) ois.readObject();

The result is now an InvalidClassException because of the serialVersionUID. To resolve this issue I have to create a custom, modified ArrayList and stoped working for now.
But with this example it would be possible to transfer every object which implements "Serializable".

Bye
Volker

Offline

#4 2008-12-19 23:22:53

Volker Brehm
Member
Registered: 2007-04-03
Posts: 1139
Website

Re: How to transmit an Object to a childjob ?

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » How to transmit an Object to a childjob ?

Board footer

Powered by FluxBB