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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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.

Labels (3)
1 Solution

Accepted Solutions
cterenzi
Specialist
Specialist

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

5 Replies
cterenzi
Specialist
Specialist

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

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!

Anonymous
Not applicable
Author

Can anyone please advise? Appreciate your help!!

 

Regards

TRF
Champion II
Champion II

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.
cterenzi
Specialist
Specialist

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.