Issue when trying to get the subtraction of two HashSets

Highlighted
Six Stars

Issue when trying to get the subtraction of two HashSets

Hi All,

The following is my scenario:

 

Set<String> cs = new HashSet<>();

cs.add(row5.c);

globalMap.put("cSet",cs);

 

Set<String> tcs = new HashSet<>();

cs.add(row5.tc);

globalMap.put("tcSet",tcs);

 

Set<String> Bn = new HashSet<>();
Bn.addAll((Set<String>)globalMap.get("cSet"));
Bn.removeAll((Set<String>)globalMap.get("tcSet"));

 

 

ERROR MESSAGE:

Exception in component tJava_2
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Set


Accepted Solutions
Highlighted
Community Manager

Re: Issue when trying to get the subtraction of two HashSets

Hi
I tested your code with a simple job, but I don't have compilation error.
tFixedFlowInput--main--tJava
Can you explain why you need to write Java code? Please give us more detailed information about your requirement, maybe you can achieve it with existing components.

Regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

View solution in original post

Highlighted
Community Manager

Re: Issue when trying to get the subtraction of two HashSets

Hi

I tested your code and it works without error, would you mind uploading your job or sending it to me via email? I will look into it further.

Regards

Shong

----------------------------------------------------------
Talend | Data Agility for Modern Business

View solution in original post


All Replies
Highlighted
Six Stars

Re: Issue when trying to get the subtraction of two HashSets

Can anybody advise? Appreciate it so much!

Highlighted
Community Manager

Re: Issue when trying to get the subtraction of two HashSets

Hi
I tested your code with a simple job, but I don't have compilation error.
tFixedFlowInput--main--tJava
Can you explain why you need to write Java code? Please give us more detailed information about your requirement, maybe you can achieve it with existing components.

Regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

View solution in original post

Highlighted
Six Stars

Re: Issue when trying to get the subtraction of two HashSets

Thanks for your reply, Shong.

 

What I want is to get the difference in those two sets. I define those two sets first and then use addAll() and removeAll() method to accomplish it, but it failed with errors. Appreciate your help!

Highlighted
Community Manager

Re: Issue when trying to get the subtraction of two HashSets

Hi

I tested your code and it works without error, would you mind uploading your job or sending it to me via email? I will look into it further.

Regards

Shong

----------------------------------------------------------
Talend | Data Agility for Modern Business

View solution in original post

Highlighted
Six Stars

Re: Issue when trying to get the subtraction of two HashSets

Thanks for your help, Shong. I just added an output following my scripts which is System.out.println(Bn), then I got what I want, thanks for your answers. 

2019 GARTNER 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

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