Skip to content

Instantly share code, notes, and snippets.

@saisgit
Created April 25, 2020 13:06
Show Gist options
  • Save saisgit/13edf012488086bc7e81a69c637391d7 to your computer and use it in GitHub Desktop.
Save saisgit/13edf012488086bc7e81a69c637391d7 to your computer and use it in GitHub Desktop.
'''
Function to Create Dataframe on RDBMS Table
Parameters: SparkSession Object, DB Username, DB password, JDBC Driver ClassName, JDBC URL, Query to run
Return: Spark Dataframe
'''
def getDFbyRDBMS(spark, user, password, driver, jdbcURL, readQuery):
prop = {"user":user, "password":password, "driver": driver, "sslConnection":"false"}
df = spark.read.jdbc(url = jdbcURL, table = readQuery, properties = prop)
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment