简体   繁体   English

在neo4j中没有标题的CSV文件

[英]CSV file with no headers in neo4j

I have a CSV file which has a similar pattern of data like below我有一个 CSV 文件,它具有类似的数据模式,如下所示

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然后我使用了以下 Cypher 查询

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所以基本上我想将 CSV 文件中的数据存储为数组列表应该出现以下 json 格式

{
  "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.感谢我的 Cypher 代码中的任何更改。

This won't work at all - if you try to store a multi-dimensional array in neo4j, you'll end up seeing this:这根本行不通 - 如果您尝试在 neo4j 中存储多维数组,您最终会看到:

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.这将使加载数据变得更加容易,并为您带来好处,即它可以利用 neo4j 做得很好的东西并且更容易查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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