
Merge Data from a Data Frame into Kuzu using a Merge Query
Source:R/kuzu_load_data.R
kuzu_merge_df.RdThis function is intended for merging data from an R data.frame into Kuzu
using a specified merge query. It leverages Python's reticulate to interact
with Kuzu's Python API.
Examples
if (FALSE) { # \dontrun{
my_data <- data.frame(
name = c("Alice", "Bob"),
item = c("Book", "Pen"),
current_city = c("New York", "London")
)
merge_statement <- "MERGE (p:Person {name: df.name})
MERGE (i:Item {name: df.item})
MERGE (p)-[:PURCHASED]->(i)
ON MATCH SET p.current_city = df.current_city
ON CREATE SET p.current_city = df.current_city"
# Note: 'conn' would need to be a valid Kuzu connection object
# and the schema (Person, Item, PURCHASED tables) would need to be created
# before running this example.
# kuzu_merge_df(conn, my_data, merge_statement)
# Example with a different merge query structure:
my_data_2 <- data.frame(
person_name = c("Charlie"),
purchased_item = c("Laptop"),
city = c("Paris")
)
#
merge_statement_2 <- "MERGE (p:Person {name: person_name})
MERGE (i:Item {name: purchased_item})
MERGE (p)-[:PURCHASED]->(i)
ON MATCH SET p.current_city = city
ON CREATE SET p.current_city = city"
# kuzu_merge_df(conn, my_data_2, merge_statement_2)
} # }