• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Ranch Hand
Posts: 228
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 334
2
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 17687
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
M Richardson
Ranch Hand
Posts: 228
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
This tiny ad is wafer thin:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic