Download PostgreSQL JDBC-driveren fra https://jdbc.postgresql.org/download.html
Erstat derefter databasekonfigurationsværdierne med dine.
from pyspark.sql import SparkSession
spark = SparkSession \
.builder \
.appName("Python Spark SQL basic example") \
.config("spark.jars", "/path_to_postgresDriver/postgresql-42.2.5.jar") \
.getOrCreate()
df = spark.read \
.format("jdbc") \
.option("url", "jdbc:postgresql://localhost:5432/databasename") \
.option("dbtable", "tablename") \
.option("user", "username") \
.option("password", "password") \
.option("driver", "org.postgresql.Driver") \
.load()
df.printSchema()
Mere info:https://spark.apache.org/docs/latest/sql-data-sources-jdbc.html