Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

connect spark to postgres; connect spark to database

spark = SparkSession.builder.config(conf=spark_conf).getOrCreate()

#make sure the necessary jar files are loaded
#@ opt/spark/jars folder

df = spark.read 
    .format("jdbc") 
    .option("url", "jdbc:postgresql://<host>:<port>/<db_name>") 
    .option("dbtable", "<schema>.<tablename>") 
    .option("user", "<username>") 
    .option("password", "<password>") 
    .option("driver", "org.postgresql.Driver") 
    .load()
 
PREVIOUS NEXT
Tagged: #connect #spark #connect #spark #database
ADD COMMENT
Topic
Name
4+3 =