Trying to use spark mongo connector with the following versions and getting an error, see below:
versions
- mongo-spark-connector-10.2.3
- SPARK_VERSION=3.5.0
- SCALA_VERSION_BASE=2.13
- SCALA_VERSION=2.13.12
Jars
- mongodb-driver-core-5.1.0.jar
- bson-5.1.0.jar
- mongo-spark-connector_2.13-10.2.3.jar
- mongodb-driver-sync-5.1.0.jar
Dockerfile: https://github.com/rockthejvm/spark-essentials/blob/master/spark-cluster/docker/base/Dockerfile
Code:
spark: SparkSession = SparkSession.builder.appName("myApp").getOrCreate() df = ( spark.read.format("mongodb") .option("database","v1") .option("collection","contacts") .option( "spark.mongodb.read.connection.uri", "mongodb+srv://xxx/", ) .load() ) filtered_df = df.filter(df["place_id"] == "id") print(filtered_df.collect()[0]) ## this fails
Error:
java.lang.NoSuchMethodError: 'org.apache.spark.sql.catalyst.encoders.ExpressionEncoder org.apache.spark.sql.catalyst.encoders.RowEncoder$.apply(org.apache.spark.sql.types.StructType)'
at com.mongodb.spark.sql.connector.schema.RowToInternalRowFunction.<init>(RowToInternalRowFunction.java:40)
at com.mongodb.spark.sql.connector.schema.BsonDocumentToRowConverter.<init>(BsonDocumentToRowConverter.java:99)
at com.mongodb.spark.sql.connector.read.MongoBatch.<init>(MongoBatch.java:47)
at com.mongodb.spark.sql.connector.read.MongoScan.toBatch(MongoScan.java:61)
- backported by
-
SPARK-413 Provide support for Spark >=v3.2.4
- Closed