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

All Replies
Six Stars

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

Can anybody advise? Appreciate it so much!

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
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!

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

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download