我以前能夠加載這個MongoDB數據庫,但我現在收到一個我一直無法弄清的錯誤。MongoDB Spark連接器py4j.protocol.Py4JJavaError:調用o50時發生錯誤.load
這裏是我開始我的星火會話:
spark = SparkSession.builder \
.master("local[*]") \
.appName("collab_rec") \
.config("spark.mongodb.input.uri", "mongodb://127.0.0.1/example.collection") \
.config("spark.mongodb.output.uri", "mongodb://127.0.0.1/example.collection") \
.getOrCreate()
我運行此腳本,這樣我可以通過IPython中至極的火花互動加載蒙戈火花連接器包:
#!/bin/bash
export PYSPARK_DRIVER_PYTHON=ipython
${SPARK_HOME}/bin/pyspark \
--master local[4] \
--executor-memory 1G \
--driver-memory 1G \
--conf spark.sql.warehouse.dir="file:///tmp/spark-warehouse" \
--packages com.databricks:spark-csv_2.11:1.5.0 \
--packages com.amazonaws:aws-java-sdk-pom:1.10.34 \
--packages org.apache.hadoop:hadoop-aws:2.7.3 \
--packages org.mongodb.spark:mongo-spark-connector_2.11:2.0.0\
星火負荷很好,它看起來包裝正確加載。
這裏是我嘗試在數據庫加載到數據幀:
df = spark.read.format("com.mongodb.spark.sql.DefaultSource").load()
然而,在該行,我收到以下錯誤:
Py4JJavaError: An error occurred while calling o46.load.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 0.0 failed 1 times, most recent failure: Lost task 0.0 in stage 0.0 (TID 0, localhost, executor driver): java.lang.NoSuchMethodError: org.apache.spark.sql.catalyst.analysis.TypeCoercion$.findTightestCommonTypeOfTwo()Lscala/Function2;
at com.mongodb.spark.sql.MongoInferSchema$.com$mongodb$spark$sql$MongoInferSchema$$compatibleType(MongoInferSchema.scala:132)
at com.mongodb.spark.sql.MongoInferSchema$$anonfun$3.apply(MongoInferSchema.scala:76)
at com.mongodb.spark.sql.MongoInferSchema$$anonfun$3.apply(MongoInferSchema.scala:76)
從我可以通過看以下文檔/教程我試圖正確加載數據幀:
https://docs.mongodb.com/spark-connector/master/python-api/
我使用Spark 2.2.0 請注意,我已經能夠通過AWS在我的Mac和Linux上覆制此錯誤。
謝謝你,你剛剛救了我很多時間! – user2359459