PySpark sqlContext读取Postgres 9.6 NullPointerException

编程入门 行业动态 更新时间:2024-10-25 12:21:19
本文介绍了PySpark sqlContext读取Postgres 9.6 NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尝试使用Postgres DB中的PySpark读取表。我设置了以下代码并验证了SparkContext的存在:

Trying to read a table with PySpark from a Postgres DB. I have set up the following code and verified SparkContext exists:

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 ,表为标本,并已使用Postgres.app macOS验证其是否在 localhost 上运行应用程序。

The name of my database is gqp, table is specimen, and have verified it is running on localhost using the Postgres.app macOS app.

推荐答案

URL出了问题!

最初是: url ='jdbc:postgresql:// tom:@ localhost / gqp'

我删除了 tom:@ 部分,它起作用了。 URL必须遵循以下格式: jdbc:postgresql:// ip_address:port / db_name ,而mine是直接从Flask项目复制的。

I removed the tom:@ part, and it worked. The URL must follow the pattern: jdbc:postgresql://ip_address:port/db_name, whereas mine was directly copied from a Flask project.

如果您正在阅读本文,希望您不要犯同样的错误:)

If you're reading this, hope you didn't make this same mistake :)

更多推荐

PySpark sqlContext读取Postgres 9.6 NullPointerException

本文发布于:2023-10-27 16:08:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533877.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:sqlContext   PySpark   Postgres   NullPointerException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!