fuzzycsv.rdbms.FuzzyCsvDbInserter.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fuzzy-csv Show documentation
Show all versions of fuzzy-csv Show documentation
A groovy/java tabular Data (from CSV,SQL,JSON) processing library that supports fuzzy column matching,tranformations/merging/querying etc
package fuzzycsv.rdbms
import fuzzycsv.FuzzyCSVTable
import fuzzycsv.Record
import fuzzycsv.rdbms.stmt.SqlRenderer
import groovy.transform.CompileStatic
import org.apache.commons.lang3.tuple.Pair
import java.util.concurrent.Callable
import java.util.stream.StreamSupport
//todo remove apache commons dependency
@CompileStatic
class FuzzyCsvDbInserter {
private FuzzyCsvDbInserter() {
}
static String inTicks(String s) {
if (s.contains('`' as CharSequence)) {
throw new IllegalArgumentException("Header cannot contain backtick")
}
return '`' + s + '`'
}
static Pair> generateUpdate(SqlRenderer sqlRenderer,
Record r,
String tableName,
String... identifiers) {
String updateStart = "UPDATE " + sqlRenderer.quoteName(tableName) + "\n"
Collection finalHeaders = r.getFinalHeaders().findAll { String h -> !identifiers.contains(h) }
List