df.select("GRID_ID","GRID_CENTROID_LON","GRID_CENTROID_LAT").distinct().write
.format("org.neo4j.spark.DataSource")
.mode(SaveMode.Append)
.option("node.keys", "GRID_ID,GRID_CENTROID_LON,GRID_CENTROID_LAT")
.option("labels", ":Grid")
.option("url", url)
.option("authentication.type", "basic")
.option("authentication.basic.username", username)
.option("authentication.basic.password", password)
.save()
This is how I can create nodes with properties but the case is that I have already created nodes and now I want to add property or add another column as a property to that node.
This is exactly how i am creating nodes and relationships. How i can add property to the node postalCode
val relationshipConfig = Map(
"CONNECTED" -> ("PostalCode", "Prefecture", "code", "Prefecture") // Corrected labels
)
// FUNCTION OF DATA INSERTION IN NEO4J
def writeToNeo4j(
finalData: DataFrame,
relationship: String,
sourceColumn: String,
targetColumn: String,
sourceLabel: String,
targetLabel: String,
url: String,
username: String,
password: String
): Unit = {
try {
println(s"Writing relationship: $relationship from $sourceLabel to $targetLabel") // Debugging
data.select(sourceColumn, targetColumn).distinct().write
.mode("Overwrite") // Use Overwrite mode carefully
.format("org.neo4j.spark.DataSource")
.option("relationship", relationship)
.option("relationship.save.strategy", "keys")
.option("relationship.source.node.keys", s"$sourceColumn") // Corrected: Just the column name
.option("relationship.target.node.keys", s"$targetColumn") // Corrected: Just the column name
// USE THIS TO PREVENT DUPLICATE RELATIONSHIPS (OPTIONAL FOR NOW)
.option("relationship.merge", "true")
// SOURCE NODE DETAILS
.option("relationship.source.save.mode", "Overwrite") // Use Overwrite mode carefully
.option("relationship.source.labels", s":$sourceLabel")
.option("relationship.source.node.properties", s"$sourceColumn") // Corrected: Just the column name
// TARGET NODE DETAILS
.option("relationship.target.save.mode", "Overwrite") // Use Overwrite mode carefully
.option("relationship.target.labels", s":$targetLabel")
.option("relationship.target.node.properties", s"$targetColumn") // Corrected: Just the column name
// NEO4J CONNECTION DETAILS
.option("url", url)
.option("authentication.type", "basic")
.option("authentication.basic.username", username)
.option("authentication.basic.password", password)
.save()
Could anyone can help me?
thanks.