Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Zurich on Sept 24th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Dazbellboy
Contributor III
Contributor III

[resolved] Use Multiple outputs with tJavaRow

Hi everyone,
I am trying to get the data from a flat file (in this case there are no delimiters, they are fixed rows), for example:

DATEVALUEDESCRIPTION
2017020320000EFFECTIVEPAY

In a tJavaRow I am applying some validations of structure and depending on the result, I want to send the data to insert it into an ORACLE database. So, for example, I validate that the text "20170203" is a valid date and if it is a valid date I want to send it by an output X to store it with an prepared statement in some table, but if it is not a valid date then I want to send it by another Output to perform an insert with another component in a different table that will log the errors. However, I can not find the way to specify more than one output with the componet.

Could anyone help me, please?

Labels (2)
1 Solution

Accepted Solutions
Dazbellboy
Contributor III
Contributor III
Author

rana.abhimanyu90 wrote:
As rhall_2.0 has mentioned using tmap variables, you can set flags(boolean vars) based on your validation requirements and create multiple outputs for tmap and based on those flag values for each row pass the value in respective output flows.

To everyone, thank you very much. I applied all your advices, it works fine... But rhall_2.0, I decided put all the validations into a tJavaRow, it seems easier... maybe it's not good for portability but I can manage the Exceptions easily.




View solution in original post

10 Replies
Anonymous
Not applicable

Hi,
From your description, you can use connection type "RunIf" which triggers a subjob or component in case the condition defined is met.
tfileinput-->tjavarow-->runif(valid data)-->inputrow-->output
                              -->runif(invalid data)-->inputrow-->output_2
Best regards
Sabrina
Anonymous
Not applicable

There is an easy way of doing this. First of all, don't use the tJavaRow for your validation logic. I'm assuming you are doing this because you have a Java background. If so, wrap your logic into a routine (a Java class using a static methods) and validate the data inside a tMap. This allows multiple outputs where you can easily specify logic to indicate exactly where you want the data to go. This tutorial from Talend might help  https://help.talend.com/search/all?query=tMap
Dazbellboy
Contributor III
Contributor III
Author

xdshi wrote:
Hi,
From your description, you can use connection type "RunIf" which triggers a subjob or component in case the condition defined is met.
tfileinput-->tjavarow-->runif(valid data)-->inputrow-->output
                              -->runif(invalid data)-->inputrow-->output_2
Best regards
Sabrina

Hi xdshi.
Well, I know I can run a subjob with a tRunJob, but I'm not sure how to transfer the output data from a tJavaRow to a tRunJob. I had to use the runIf invoking a new File. Please see my screenshot

I obtain the list files with the tFileList, then I load the file in the tFileInputPositional with a ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")) and the data validation is done with the JavaRow (rhall says that I can do the validations in a tMap, but tMap use the minimum java knowledge and I need import librarys such as java.util.regex or java.text.SimpleDateFormat) so, after the validations, in order to get the data from the tJavaRow, I just had to reload the file to get the line I need to insert in ORACLE.

Thank you very much for your help... However, I need find another solution.
Dazbellboy
Contributor III
Contributor III
Author

rhall_2.0 wrote:
There is an easy way of doing this. First of all, don't use the tJavaRow for your validation logic. I'm assuming you are doing this because you have a Java background. If so, wrap your logic into a routine (a Java class using a static methods) and validate the data inside a tMap. This allows multiple outputs where you can easily specify logic to indicate exactly where you want the data to go. This tutorial from Talend might help  https://help.talend.com/search/all?query=tMap

Hi rhall, Thanks for your answer.
Just as I told xdshi, I can't implement complex Java logic with the tMap (at least, I don't know how). I can work with a routine made by me, but I can't specify the output into a tMap (If the data is valid, then send it to the tMap output X, if the data is invalid, then send it to the output Y)... That is what I got from your answer.
Anonymous
Not applicable

All of your logic can be contained with a tMap. Take a look at the link I posted n my last post. That will show you how you can push your data in different directions with a tMap. With regard to your complex logic, you can write routines (Java classes with static methods) which can be called inside the tMaps. You have the concept of tMap variables which are processed from top to bottom and hold their values between rows (very important and useful to remember). You can use these to call your routine methods. 
cterenzi
Specialist
Specialist

Can you add a column to the tJavaRow output that specifies the "direction" you want it to go?  If so, it would be a simple matter to split the output using a tMap with a simple conditional on your new column.
Anonymous
Not applicable

As rhall_2.0 has mentioned using tmap variables, you can set flags(boolean vars) based on your validation requirements and create multiple outputs for tmap and based on those flag values for each row pass the value in respective output flows.
Dazbellboy
Contributor III
Contributor III
Author

rana.abhimanyu90 wrote:
As rhall_2.0 has mentioned using tmap variables, you can set flags(boolean vars) based on your validation requirements and create multiple outputs for tmap and based on those flag values for each row pass the value in respective output flows.

To everyone, thank you very much. I applied all your advices, it works fine... But rhall_2.0, I decided put all the validations into a tJavaRow, it seems easier... maybe it's not good for portability but I can manage the Exceptions easily.




Dazbellboy
Contributor III
Contributor III
Author

dazbellboy wrote:
rana.abhimanyu90 wrote:
As rhall_2.0 has mentioned using tmap variables, you can set flags(boolean vars) based on your validation requirements and create multiple outputs for tmap and based on those flag values for each row pass the value in respective output flows.

To everyone, thank you very much. I applied all your advices, it works fine... But rhall_2.0, I decided put all the validations into a tJavaRow, it seems easier... maybe it's not good for portability but I can manage the Exceptions easily.
https://www.talendforge.org/forum/img/members/411227/mini_blob_20170323-1857.png

https://www.talendforge.org/forum/img/members/411227/mini_blob_20170323-1858.png

https://www.talendforge.org/forum/img/members/411227/mini_blob_20170323-1900.png

That's how I choose the output in the tmap: