I have already created node and relationships through spark datasource like this :-
val relationshipConfig = Map(
"CONNECTED" -> ("PostalCode", "Prefecture", "PostalCode", "Prefecture")
)
// FUNCTION TO CREATE RELATIONSHIPS & NODES
def writeToNeo4j(
finalData: DataFrame,
relationship: String,
sourceColumn: String,
targetColumn: String,
sourceLabel: String,
targetLabel: String,
url: String,
username: String,
password: String
): Unit = {
println(s"Writing relationship: $relationship from $sourceLabel to $targetLabel")
finalData.select(sourceColumn, targetColumn).distinct().write
.mode("Append")
.format("org.neo4j.spark.DataSource")
.option("relationship", relationship)
.option("relationship.save.strategy", "keys")
.option("relationship.source.node.keys", s"$sourceColumn")
.option("relationship.target.node.keys", s"$targetColumn")
.option("relationship.merge", "true") // Important: Use merge for relationships
.option("relationship.source.save.mode", "Append")
.option("relationship.source.labels", s":$sourceLabel")
.option("relationship.source.node.properties", s"$sourceColumn")
.option("relationship.target.save.mode", "Append")
.option("relationship.target.labels", s":$targetLabel")
.option("relationship.target.node.properties", s"$targetColumn")
.option("url", url)
.option("authentication.type", "basic")
.option("authentication.basic.username", username)
.option("authentication.basic.password", password)
.save()
relationshipConfig.foreach { case (relationship, (sourceLabel,
targetLabel, sourceColumn, targetColumn)) =>
writeToNeo4j(finalData, relationship, sourceColumn, targetColumn,
sourceLabel, targetLabel, url, username, password)
}
So in my neo4j browser i have two nodes PostalCode and Prefecture and having relationship between both.
now the case is i want to add property in node PostalCode. How i can do that? How i can modify my this code or add a function to update node to add property?
I have saw this cypher query.
MATCH (n:PostalCode)
SET n.City = 'xyz'
RETURN n
but I want a solution correspond to this in spark datasource.
@conker84
Any help would be really Appreciated!
Thanks.