Passing a global Map variable in the schema name.

Four Stars

Passing a global Map variable in the schema name.

I got null values when I passed a global map variable as a schema name in the query.  Even though, there's a value that pass from tlogRow.   Below is my job.

 

 

etl1.JPG

etl2.JPG

 

It should be getting the value = flcbmtg.  Can you please help me on this?

 

etl3.JPG

Community Manager

Re: Passing a global Map variable in the schema name.

There are a couple of things wrong where you use your globalMap. First of all, the tFlowToIterate names the globalMap key using the row that feeds it and the column name. The row that feeds it is row4 not row1. The other issue is that you will need to cast that value from Object. The globalMap will default all objects to Object. To do this, just use the following code....

 

((String)globalMap.get("row4.current_schema"))

 

Four Stars

Re: Passing a global Map variable in the schema name.

Thank you...

But I'm still getting this error.  Is it possible that it cannot process the schema that global map variable is getting?

 

etl4.JPG

Community Manager

Re: Passing a global Map variable in the schema name.

OK, deactivate your DB component and everything after that. Add a tJava after the tFlowToIterate component. Then  add your query String to the tJava and save it to a String variable. Then use a System.out.println() call to print that query to the output window. This will show you what is not working properly. If the output from this works in your DB query analyser, then it will work in Talend.

Four Stars

Re: Passing a global Map variable in the schema name.

Thanks again.

 

I did put the global variable in TJavarow and its getting the schema that I need, it's just that when I replace it here:

 

FROM \""+context.tandem_Database+"\".\""+((String)globalMap.get("row4.current_schema"))+"\".\"party_contacts\"

 

It's reading it like null.party_contacts

Community Manager

Re: Passing a global Map variable in the schema name.

Look at your previous error message and the error message you are getting for this. They are different. So the globalMap call change has done something. You need to know the SQL that is generated by that String manipulation and then test that SQL. If you try out what I suggested it will print the SQL that is generated so that you can test or see what is happening. 

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 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog