Skip to content

Instantly share code, notes, and snippets.

@derms
Created March 7, 2019 10:59
Show Gist options
  • Save derms/4d1b4f841415c7029d01d39c57ee93d8 to your computer and use it in GitHub Desktop.
Save derms/4d1b4f841415c7029d01d39c57ee93d8 to your computer and use it in GitHub Desktop.
Count Lines in CSV's before MLCP
task importSampleData(type: com.marklogic.gradle.task.MlcpTask) {
def directory = "./sample-dir/" // can get this from gradle properties
//parse csv files
doFirst {
println "\nSTART: Reading files"
def totalLineCount = 0
fileTree(directory).each{ file ->
def filename = file.getName()
def lineCount = java.nio.file.Files.lines(file.toPath()).count() -1;
println "${filename} has ${lineCount} lines (excluding header)"
totalLineCount = totalLineCount + lineCount
}
println "FINISHED: Reading files"
println "TOTAL LINE COUNT (excluding headers): ${totalLineCount}\n"
}
//standard mlcp config
classpath = configurations.mlcp
command = "IMPORT"
port = Integer.parseInt(mlStagingPort)
database = mlStagingDbName
input_file_path = directory
input_file_type = "delimited_text"
delimiter = ";"
output_collections = "sample,input"
output_permissions = "rest-reader,read,rest-writer,update"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment