Dynamic Regex in tExtractRegexFields

One Star

Dynamic Regex in tExtractRegexFields

My job is
tJavaRow ------>  tExtractRegexFields
I check some condition in tJavaRow and set the regex value to output_row.RegexPattern and try to access it in tExtractRegexFields in Regex property like input_row.RegexPattern, but I am getting null value. I don't understand why regex value is not getting set. In short, I want Regex property of tExtractRegexFields dynamic.
Please help me on this.

Seventeen Stars

Re: Dynamic Regex in tExtractRegexFields

hi

you right, tJavaRow use the syntax input_row & output_row ... but in other component use nameofRow.nameofField (ex : row1.RegexPattern)

hope it helps

regards
laurent
One Star

Re: Dynamic Regex in tExtractRegexFields

Thanks.
I tried it but no luck. Actually If I put static regex pattern it works, but when I try dynamic regex then it fails. Even I tried to set regex in global map at start and tried to use it in regex field but it didn't work.
Seventeen Stars

Re: Dynamic Regex in tExtractRegexFields

the regex doesn't match what you expect or you've an error?
what's one of your regex are trying to play ?

regards
One Star

Re: Dynamic Regex in tExtractRegexFields

When I put the hard coded regex pattern in Regex field of tExtractRegexField then it works fine and same regex pattern
When I set in context or global map and try to get the regex pattern in tExtractRegexField ((String)globalMap.get("regex_pattern")) then I get null pointer exception.
Seventeen Stars

Re: Dynamic Regex in tExtractRegexFields

if you compare (String)globalMap.get("regex_pattern") & hard coded pattern, are they the same ? (use a System.out.println() to log value from globalmap).
I suspect some backslash added or those kind of things that escape special caracters.

Can you post your regex & a sample of your data input ?

regards
One Star

Re: Dynamic Regex in tExtractRegexFields

Yes I ensured that both patterns are same
Seventeen Stars

Re: Dynamic Regex in tExtractRegexFields

so the only reason is that your var (String)globalMap.get("regex_pattern") = null when you're trying to use it.
One Star

Re: Dynamic Regex in tExtractRegexFields

Yes. My job flow is :-
tFileInputSendMail  ->  tJava -> tExtractRegexField
In tJava, I set the regex pattern to variable (MyRegex.regex = "regex pattern") and try to use it in tExtractRegexField (MyRegex.regex), I get it null.
When I move tJava before tFIleInputSendMail then it works fine. As per code, I can see regex compilation happens before value is set to variable.
Seventeen Stars

Re: Dynamic Regex in tExtractRegexFields

tjava cannot manage flow (MyRegex.regex ) => use tjavarow for that or initialize a global var : globalMap.put("regex',"regex pattern")
& use it with (String)globalMap.get("regex")

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch