Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

import - Add the first row of csv as the attributes of a node type - Neo4J

I have csv with a lot of columns, which is why it's not a productive and automatic way to add all columns as attributes by hand when writing a query. The csv has the first row with the names of the columns, and the remaining rows represent the nodes with the values of the attributes.

I tried to add the attributes using SET += but doesn't work.

LOAD CSV FROM 'file:///stations.csv' AS row
WITH row LIMIT 1
UNWIND row as att
WITH att
CREATE(n:Station)
SET n += att

question from:https://stackoverflow.com/questions/66066668/add-the-first-row-of-csv-as-the-attributes-of-a-node-type-neo4j

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It would be best to choose only the few properties that are really needed "in the graph", and only load those. Generally speaking it is not best practice to replicate a relational data store table structure (with large column counts) inside Neo4j, first sketch out a new graph meta-model, then load it, this usually requires some ETL steps, and often data cleaning. One can sketch out the meta-model on paper with a pencil, or using the arrows tool, which provides a more polished diagram if needed for the documentation.

Note, I can however envision a need to dynamically handle the property list, perhaps the property list is short but always changing? I imagine there are several ways to do it, but off the top of my head one way would be to dynamically build the cypher statement in a string and then execute it using this APOC call

CALL apoc.cypher.run()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...