Three Stars

Multiple rows output (or custom tNormalize)

Hi,

so I have data set of various concatenated phone numbers, like:

+44 1632960755, +441632960996
+44 1632 960190;1632960383,+44 1632 960610
+441632960839

I need to normalize them, but they have different separators, formats etc., so tNormalize is a no-go.

The best option I found is libphonenumber and what I need is to use findNumbers method which returns an Iterable, then go through each of the returned items and call some other methods from the library - isValid, getExtension etc.

And I cannot make it work in Talend - if I use tJavaRow, I only can output one row (and findNumbers can find several ones).

Sure, I can use tJavaRow to findNumbers, concatenate the results and then use tNormalize and then call another tJavaRow step to calculate the rest of methods, but it seems an unnecessarily complicated way. I tried to use tJavaFlex with no luck.

tJavaFlex.PNG

So is there any way to output multiple rows from tJavaRow or tJavaFlex? Or any other more robust solution than tJavaRow > tNormalize > tJavaRow?

1 ACCEPTED SOLUTION

Accepted Solutions
Twelve Stars

Re: Multiple rows output (or custom tNormalize)

I think you are close, but you are using the tJavaFlex slightly incorrectly. But you are not too far off. The tJavaFlex works in 3 stages; the Start Code section fires when the component is being initialised, the Main Code is fired for every row and the End Code is fired at the end. So in your example, you cannot use a "row" value in the Start Code section. However, you can get around this. Take a look at this tutorial in row multiplication (https://www.rilhia.com/quicktips/quick-tip-row-multiplication). What I am doing here is using a tJavaFlex as a lookup with a tMap. I am initialising it with each row, which means that I can supply a row value to the Start Code in the globalMap. Rework your code (which is practically there) with reference to what I do in the tutorial, and this will work. 

Rilhia Solutions
3 REPLIES
Twelve Stars

Re: Multiple rows output (or custom tNormalize)

I think you are close, but you are using the tJavaFlex slightly incorrectly. But you are not too far off. The tJavaFlex works in 3 stages; the Start Code section fires when the component is being initialised, the Main Code is fired for every row and the End Code is fired at the end. So in your example, you cannot use a "row" value in the Start Code section. However, you can get around this. Take a look at this tutorial in row multiplication (https://www.rilhia.com/quicktips/quick-tip-row-multiplication). What I am doing here is using a tJavaFlex as a lookup with a tMap. I am initialising it with each row, which means that I can supply a row value to the Start Code in the globalMap. Rework your code (which is practically there) with reference to what I do in the tutorial, and this will work. 

Rilhia Solutions
Three Stars

Re: Multiple rows output (or custom tNormalize)

Not sure how it works yet, but it works!

I think you could improve your blog post a bit - "you cannot use row output in the start section, so you have to first put the data in globalMap" or something Smiley Happy 

Thanks anyway!

Twelve Stars

Re: Multiple rows output (or custom tNormalize)

Thanks, I will take a look and see if I can improve it a little. I don't give myself a great deal of time to write these tutorials and they are usually written in spare moments. So there is plenty of room for improvement :-)

Rilhia Solutions