Skip to content

Instantly share code, notes, and snippets.

@sjanahan
Created September 2, 2016 16:28
Show Gist options
  • Save sjanahan/74dfe1e3f191855bd115fed4cbc8cd69 to your computer and use it in GitHub Desktop.
Save sjanahan/74dfe1e3f191855bd115fed4cbc8cd69 to your computer and use it in GitHub Desktop.
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