Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def upload(csv: File): Unit = {
val conn = dBUtil.getJDBC
val tableName = "weather"
// Export table as CSV using the /copy command
val copyManager = new CopyManager(conn.asInstanceOf[BaseConnection])
val currentDirectory = new java.io.File(".").getCanonicalPath
println(currentDirectory)
val pathOfCopiedOutFile = currentDirectory + "/" + tableName + ".csv"
println(pathOfCopiedOutFile)
val copyCmd = "COPY " + tableName + " TO '" + pathOfCopiedOutFile + "' DELIMITER ',' CSV HEADER"
println(copyCmd)
val copiedOutFile = new File(pathOfCopiedOutFile)
try {
copyManager.copyOut(copyCmd)
}
catch{
case e: Exception => println(ErrorUtil.getStackTraceAsString(e))
}
println("uploading to s3...")
println(tableName)
client.putObject(bucketName, tableName, copiedOutFile)
println("done uploading :)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.