My goal is to load some documents that are loaded as RDD in Apache Spark into a Neo4j Graph. The issue seems to be with the creation of such nodes because Eclipse reports the task not being serialiazable
Exception in thread "main" org.apache.spark.SparkException: Task not serializable
My code is the following:
public class Spark {
public static void createRdd() {
SparkSession spark = SparkSession.builder()
.master("local")
.appName("MongoSparkConnector")
.config("spark.mongodb.input.uri", "mongodb://127.0.0.1/TheFoodPlanner.join")
.getOrCreate();
JavaSparkContext jsc = new JavaSparkContext(spark.sparkContext());
JavaMongoRDD<Document> rddRecipes = MongoSpark.load(jsc);
Driver driver = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic("neo4j", "estrella100"));
try (Session session = driver.session()) {
rddRecipes.foreach(f -> {
String id = f.getString("id");
session.run("CREATE (n: Recipe {id:'" + id + "'})");
});
session.close();
}
driver.close();
jsc.close();
}
}
and the error appears in the line session.run("CREATE (n: Recipe {id:'" + id + "'})");
What would be the correct way to load the nodes in paralel?