Skip to content

Instantly share code, notes, and snippets.

@saisgit
Created July 25, 2021 16:16
Show Gist options
  • Save saisgit/c67043e92370edaffb11c3d7059a6406 to your computer and use it in GitHub Desktop.
Save saisgit/c67043e92370edaffb11c3d7059a6406 to your computer and use it in GitHub Desktop.
// 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