Created
September 2, 2016 16:28
-
-
Save sjanahan/74dfe1e3f191855bd115fed4cbc8cd69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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