Skip to content

Instantly share code, notes, and snippets.

@seahrh
Created April 25, 2019 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seahrh/523833dbaee6e2d76d780f19b4586d6d to your computer and use it in GitHub Desktop.
Save seahrh/523833dbaee6e2d76d780f19b4586d6d to your computer and use it in GitHub Desktop.
spark read jdbc
import org.apache.spark.sql._
final case class QueryReader(
spark: SparkSession,
query: String,
url: String,
driver: String,
user: String,
password: String
) {
private def read(source: String): DataFrame = {
spark.read.format(source).option("url", url)
.option("driver", driver)
.option("user", user)
.option("password", password)
.option("dbtable", query)
.load()
}
def jdbc: DataFrame = {
read("jdbc")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment