• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to compare two datasets to check for missing rows which don't exist in the other dataset?  RSS feed

 
Mark Richardson
Ranch Hand
Posts: 108
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have built a method which takes two datasets: dataset1 and retirementSimpleData. It matches the two datasets based on a primary key/number, defined as cnum, in the code below. I wanted to return the value of the difference between the getAssets value and the getSums value, and this is working, except for one little problem.

Some of the cnums that exist in dataset1 don't exist in retirementSimpleData. Similarly, some cnums which may exist in retirementSimpleData may not exist in dataset1. This is resulting in no data being returned for that cnum

I would like to implement two passes at the end which check in one direction to see if I missed anything. The second pass would check in the opposite direction. However, not sure how I would go about implementing this.




Caveat: dataset1 and retirementSimpledata both use existing SQL pulls which I am not allowed to touch, otherwise I would have simply defined new SQL for these methods in my "DAOImpl." Therefore, I have to work with the data I am getting, and programmatically check for this.
 
Joe Areeda
Ranch Hand
Posts: 334
2
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The operation you need are available in the Set interface.  Classes TreeSet or HashSet have addAll and removeAll methods.

One approach would be to build 2 sets od cnums from the lists  something like



Note I didn't compile or test it, so consider it pseudo-code

Joe

 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another approach would be to use the appropriate join query and let the database do the work for you. Then your Java code can just process the results that came back from the DB Query.
 
Mark Richardson
Ranch Hand
Posts: 108
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:Another approach would be to use the appropriate join query and let the database do the work for you. Then your Java code can just process the results that came back from the DB Query.


Yep! That would make more sense, but in this example, I wasn't allowed to touch any of the queries and was told to simply re-use what is there... which made it trickier.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!