1
嘗試從Postgres數據庫讀PySpark表。我已經建立了下面的代碼和驗證SparkContext存在:PySpark sqlContext閱讀Postgres 9.6空指針異常
import os
os.environ['PYSPARK_SUBMIT_ARGS'] = '--driver-class-path /tmp/jars/postgresql-42.0.0.jar --jars /tmp/jars/postgresql-42.0.0.jar pyspark-shell'
from pyspark import SparkContext, SparkConf
conf = SparkConf()
conf.setMaster("local[*]")
conf.setAppName('pyspark')
sc = SparkContext(conf=conf)
from pyspark.sql import SQLContext
properties = {
"driver": "org.postgresql.Driver"
}
url = 'jdbc:postgresql://tom:@localhost/gqp'
sqlContext = SQLContext(sc)
sqlContext.read \
.format("jdbc") \
.option("url", url) \
.option("driver", properties["driver"]) \
.option("dbtable", "specimen") \
.load()
我收到以下錯誤:
Py4JJavaError: An error occurred while calling o812.load. : java.lang.NullPointerException
我的數據庫的名稱是gqp
,表是specimen
,並驗證它在運行在localhost
使用Postgres.app macOS應用程序。