esProc Finds Differences between CSV files

userName and date are the logical primary key of both old.csv file and new.csv file, in which we want to find rows that are new, deleted and updated.

The source data is as follows:



As can be seen from the above data, in new.csv the 2nd and the 3rd row are the new and the 4th row is the updated; in old.csv the 3rd row is the deleted.

esProc code:


A1,B1:Retrieve the comma-separated files.

A2,B2:Sort data by the key, as this is required by the following merge function.

A3:Find the new records by the key. merge function is used to merge data sets. @d means calculating the difference during the merge. Similar options include @u for union and @i for intersection. The computed result is as follows:


A4:Find the deleted records by the key. The computed result is as follows:


A5:Take the key fields as ordinary ones to find the updated records. The computed result is as follows:


A6:A5 is an intermediate result. We need to calculate the difference between A5 and the new records to get the updated records. The computed result is as follows:



B6:Return A6 to JAVA program or the reporting tool.

Now all data processing work has been finished. We’ll then integrate the esProc script into JAVA program via JDBC. The JAVA code is as follows:

//establish a connection via esProc JDBC


         con= DriverManager.getConnection(“jdbc:esproc:local://”);

         //call esProc script, whose name is test and that can accept parameters

         st =(com.esproc.jdbc.InternalCStatement)con.prepareCall(“call test()”);

         st.execute();//execute esProc stored procedure

         ResultSet set = st.getResultSet();//get the result

If you want to return multiple data sets to the JAVA program, you can modify B6’s code into result new,delete,update.


About datathinker

a technical consultant on Database performance optimization, Database storage expansion, Off-database computation. personal blog at: datakeywrod, website: raqsoft
This entry was posted in esProc/R/Python/Perl, Structured Data Process and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s