How To Get Values In HashMap Using globalMap.get()

Highlighted
Six Stars

How To Get Values In HashMap Using globalMap.get()

Hi, my scenario is like:

 

Map<String, HashSet<String>> B = new HashMap<String, HashSet<String>>();

if(!B.containsKey(row5.issue)){
B.put(row5.issue,new HashSet<String>());
}
B.get(row5.issue).add(row5.name);

globalMap.put("BMap", B);

 

 

Now, I have the following scripts in another Subjob:

 

select * from Table

where name in ('"+BMap.values()+"');

 

 

The bold portion has problems, anyone can advise? Thanks very much.


Accepted Solutions
Ten Stars

Re: How To Get Values In HashMap Using globalMap.get()

You need to "get" BMap before you can act on it.
e.g.
((HashMap)globalMap.get("BMap")).values()

As @TRF noted, the values method does not return a String that you can drop in to your SQL statement. With your current implementation, you'll need to iterate over the Collection it returns and build a String to include in your where clause.

If this is the only use of the HashMap in your project, you may want to consider a different approach.

View solution in original post


All Replies
Ten Stars

Re: How To Get Values In HashMap Using globalMap.get()

You can't reference globalMap variables directly. You have to retrieve them, casting them to the appropriate data type. Ex:
(String)globalMap.get("exampleVariable")
Six Stars

Re: How To Get Values In HashMap Using globalMap.get()

Thanks for the reply!

 

This is what my scripts look like:

where name in ('"+((String)globalMap.get("BMap.values()"))+"');

 

But that can't go through. Thanks again for your reply!

Six Stars

Re: How To Get Values In HashMap Using globalMap.get()

Can anyone please advise? Appreciate your help!!

 

Regards

Sixteen Stars TRF
Sixteen Stars

Re: How To Get Values In HashMap Using globalMap.get()

You should build the "inString" in the 1st part instead of store indivual values of row5.name in a hashmap or you need to extract values one by one and concatenate them with ' and , to build a valid SQL string before to use it.

TRF
Ten Stars

Re: How To Get Values In HashMap Using globalMap.get()

You need to "get" BMap before you can act on it.
e.g.
((HashMap)globalMap.get("BMap")).values()

As @TRF noted, the values method does not return a String that you can drop in to your SQL statement. With your current implementation, you'll need to iterate over the Collection it returns and build a String to include in your where clause.

If this is the only use of the HashMap in your project, you may want to consider a different approach.

View solution in original post

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

Put Massive Amounts of Data to Work

Learn how to make your data more available, reduce costs and cut your build time

Watch Now

How OTTO Utilizes Big Data to Deliver Personalized Experiences

Read about OTTO's experiences with Big Data and Personalized Experiences

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog