Judge whether two csv files have same content
Here are one source csv file and two target csv files. Between them the orders of their columns may be different and orders of row values could also be different:
source.csv |
target1.csv |
target2.csv |
a,b,c 1,2,3 4,5,6 10,11,12 |
a,c,b 1,3,2 10,12,11 4,6,5 |
a,c,b 1,2,3 10,12,11 4,6,5 |
We want to use Java to judge whether the source csv file and the target csv files have same content. For the source file and one of the two files whose original columns orders are different, after they are adjusted to have the same order, if the sets made up of their rows respectively are equal, they have the same content. In the above files, source.csv and target1.csv have same content, but source.csv and target2.csv do not have the same content.
SPL code:
A |
B |
|
1 |
=file(arg_source).import@cw() |
=file(arg_target).import@cw() |
2 |
=B1(1).align@p(A1(1)) |
=B1.(~.m(A2)) |
3 |
=A1.eq(B2) |
import@cw function parses a file according to the comma separator and reads it as a sequence of sequences. align()function aligns a sequence according to the order of a specified sequence and returns ordinal numbers of members in the specified sequence. Symbol ~ represents the current member in the loop; m() function gets value of a member by its ordinal number. eq() function judges whether members of two sequences are equal.
Read How to Call a SPL Script in Java to find how to integrate SPL into a Java application.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL