简体   繁体   中英

CSV file with no headers in neo4j

I have a CSV file which has a similar pattern of data like below

1,2,3,4,5,6
7,8,9,1,2,3
4,5,6,7,8,9
1,2,3,4,5,6
7,8,9,1,2,3
4,5,6,7,8,9

Then I used the following Cypher query

CREATE CONSTRAINT ON (t:Timestamp) ASSERT t.date IS UNIQUE;

LOAD CSV FROM "file:///example.csv" AS line
MERGE (t:Timestamp) ON CREATE SET t.date: timestamp(), data:split(line,",")})

So basically I want to store data from CSV file as a list of arrays The following json format should appear

{
  "date" = "271020170000"
  "data" = [[1,2,3,4,5,6],
            [7,8,9,1,2,3],
            [4,5,6,7,8,9],
            [1,2,3,4,5,6],
            [7,8,9,1,2,3],
            [4,5,6,7,8,9]]
}

One more question is regarding timestamp, it is giving me error. I want to make the timestamp appear whenever a new data is uploaded.

Any changes in my Cypher code is appreciated.

This won't work at all - if you try to store a multi-dimensional array in neo4j, you'll end up seeing this:

Collections containing collections can not be stored in properties.

So, you have two options. You can store a flat array that's not multi-dimensional, doing something like this:

MERGE (t:Timestamp { load: "thistle" }) 
ON CREATE SET t.date: timestamp()
SET t.data = t.data + split(line,",")

Second option is to not use an array at all, which is what I would recommend. You need a better graph model for this data whatever it is (you haven't really specified). Consider breaking those values out into more than one node and a set of relationships between them. This will make it much easier to load the data and give you the benefit that it'll take advantage of the things neo4j does well and be easier to query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM