我想用pyspark把数据输入neo4j。我尝试了以下代码。
from pyspark.sql import SparkSession
spark = SparkSession.builder.master("local[1]") \
.appName("SparkByExamples.com") \
.getOrCreate()
df = spark.read.csv("countries.csv")
df.write \
.format("org.neo4j.spark.DataSource") \
.mode("ErrorIfExists") \
.option("url", "bolt://localhost:7687") \
.option("labels", ":Countries") \
.save()
但它给了我这样一个错误:
2020-11-11 17:49:19 WARN Utils:66 - Set SPARK_LOCAL_IP if you need to bind to another address
2020-11-11 17:49:20 WARN NativeCodeLoader:62 - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
Traceback (most recent call last):
File "xxx", line 13, in <module>
.option("labels", ":Countries") \
File "/opt/spark/spark-2.4.0-bin-hadoop2.7/python/pyspark/sql/readwriter.py", line 734, in save
self._jwrite.save()
File "/opt/spark/spark-2.4.0-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py", line 1257, in __call__
File "/opt/spark/spark-2.4.0-bin-hadoop2.7/python/pyspark/sql/utils.py", line 63, in deco
return f(*a,**kw)
File "/opt/spark/spark-2.4.0-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/protocol.py", line 328, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o40.save.
: java.lang.ClassNotFoundException: Failed to find data source: org.neo4j.spark.DataSource. Please find packages at http://spark.apache.org/third-party-projects.html
at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:657)
有人能帮我克服这个问题吗?先谢谢你。
1条答案
按热度按时间ktecyv1j1#
问题出在你的格式上。您需要将包包含到spark应用程序中
尝试