Last active
June 23, 2022 20:04
-
-
Save jmrr/59704142a608edad4e12 to your computer and use it in GitHub Desktop.
MySQL tables to parquet files on the Spark shell
This file contains hidden or 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
val sqlContext = new org.apache.spark.sql.SQLContext(sc) // optional | |
val df = sqlContext.load("jdbc", Map( | |
"url" -> "jdbc:mysql://<ip.address.your.db>/<table>?user=<username>&password=<pwd>", | |
"dbtable" -> "<tablename>")) | |
df.select("<col1>","<col2>","<col3>").save("</path/to/parquet/file.parquet>","parquet") | |
//Alternatively, to save all the columns: | |
df.write.parquet("</path/to/parquet/file.parquet>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment