Skip to content

Instantly share code, notes, and snippets.

@peysal
Created March 13, 2014 08:51
Show Gist options
  • Select an option

  • Save peysal/9524616 to your computer and use it in GitHub Desktop.

Select an option

Save peysal/9524616 to your computer and use it in GitHub Desktop.
package main.groovy.fp
def isHeader = true
def columns = []
def records1stFile = []
println "1st file ACCOUNT-after.csv"
new File("ACCOUNT-after.csv").eachLine { line ->
if (isHeader) {
columns = line.split(",")
println columns.size()
isHeader = false
} else {
records1stFile << line
println "size columns per record " + line.split(",").size()
}
}
println "records size:" + records1stFile.size()
isHeader = true
def records2ndFile = []
println "2nd file ACCOUNT-before.csv"
new File("ACCOUNT-before.csv").eachLine { line ->
if (isHeader) {
def columns2 = line.split(",")
assert columns2.size() == columns.size()
println columns2.size()
isHeader = false
} else {
records2ndFile << line
println "size columns per record " + line.split(",").size()
}
}
println "records size:" + records2ndFile.size()
println "---start comparing per field in records---"
def errorlines = [:]
//assuming the record are at same location for both table
for (int i = 0; i < records1stFile.size(); i++) {
def fields1stFile = records1stFile[i].split(",")
def fields2ndFile = records2ndFile[i].split(",")
assert fields1stFile.size() == fields2ndFile.size()
println "we are at line $i"
def errors = [:]
for (int v = 0; v < fields1stFile.size(); v++) {
if (!fields1stFile[v].equals(fields2ndFile[v].replace(/"/, ''))) {
errors[columns[v]] = [fields1stFile[v], fields2ndFile[v]] //error in
errorlines["line" + i + " accountId:" + fields1stFile[1]] = errors
}
}
}
if (!errorlines.isEmpty()) {
println "---------show all error in the world ---------"
errorlines.each { errorLine ->
println errorLine
}
} else {
println "Zero error!!"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment