Created
July 25, 2021 16:16
-
-
Save saisgit/c67043e92370edaffb11c3d7059a6406 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
// Read JDBC Configuration from ENV Variables | |
val JDBC_URL: String = sys.env("JDBC_URL") | |
val JDBC_USERNAME: String = sys.env("JDBC_USERNAME") | |
val JDBC_PASSWORD: String = sys.env("JDBC_PASSWORD") | |
val JDBC_DRIVER: String = "com.mysql.jdbc.Driver" | |
val tableName: String = "k9JPOiHGpv.world_city_population" | |
// Define JDBC Read Options | |
val readOptions: Map[String, String] = Map( | |
"driver" -> JDBC_DRIVER, | |
"url" -> JDBC_URL, | |
"user" -> JDBC_USERNAME, | |
"password" -> JDBC_PASSWORD, | |
"dbtable" -> tableName | |
) | |
// JDBC DataFrame with only one Partition - Spark Default JDBC Read Configuration | |
val mysql = ( | |
spark.read | |
.options(readOptions) | |
.format("jdbc") | |
.load() | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment