Cypher 读取 CSV,为数据集添加标签并创建索引

huangapple go评论62阅读模式
英文:

Cypher read CSV, add label to dataset and create index

问题

使用Cypher语言,我想要读取两个CSV文件,为它们添加标签,对某些字段定义索引,最后通过两个数据集之间的共同字段关联它们。

我该如何做呢?类似于这样:

USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM 'file:///1.csv' AS row
CREATE (:A {PROGRAM_CODE:row.PRODUCT_CODE, PRODUCT_NAME:row.PROGRAM_NAME, Stuid:row.CUSTOMER_NO})
CREATE INDEX ON :A(PROGRAM_CODE)
CREATE INDEX ON :A(CUSTOMER_NO)
RETURN count(A);


对于第二个CSV,同样以B为标签读取,然后通过A.CUSTOMER_NO和B.CUSTOMER_NO建立关系,最后可视化图形显示PRODUCT_NAMES和顾客之间的关系。

谢谢
英文:

In Cypher, I want to read two CSV files, add labels to them, define indexes on some fields, and finally relate the two datasets by a common field between the two.

How can i do that? Something like this:

USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM 'file:///1.csv' AS row
CREATE (:A {PROGRAM_CODE:row.PRODUCT_CODE,PRODUCT_NAME:row.PROGRAM_NAME,Stuid:row.CUSTOMER_NO})
CREATE INDEX ON :A(PROGRAM_CODE)
CREATE INDEX ON :A(CUSTOMER_NO)
RETURN count(A);

The same for reading the second CSV as labelled B, and then make relation On A.CUSTOMER_NO and B.CUSTOMER_NO and finally visualize the graph showing the PRODUCT_NAMES and Customers as relations.

Thanks

答案1

得分: 0

以下是已翻译的内容:

"Creating the constraint that CUSTOMER_NO is a node key means the property must exist and be unique for each node. The constraint exists in the database even if there are no A nodes.

If you just want an index and not a key:

Extra tip: While Cypher lets you label nodes, relationships, and properties however you wish, the naming conventions are:
labels: LabelName (caps starting at first word)
properties: customerNo (caps starting at second word)
relationships: MY_RELATIONSHIP (all caps, underscores)

That makes it easier to understand the structure from just looking at the code. Cypher 读取 CSV,为数据集添加标签并创建索引

Hope that helps!"

英文:

It sounds like you want to do something like this:

CREATE CONSTRAINT CUSTOMER_NO_CONSTRAINT IF NOT EXISTS
FOR (n:A) REQUIRE n.CUSTOMER_NO IS NODE KEY

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///1.csv' as row
CREATE (:A {PROGRAM_CODE:row.PRODUCT_CODE, PRODUCT_NAME:row.PROGRAM_NAME, Stuid:row.CUSTOMER_NO})

Creating the constraint that CUSTOMER_NO is a node key means the property must exist and be unique for each node. The constraint exists in the database even if there are no A nodes.

If you just want an index and not a key:

CREATE BTREE INDEX CUSTOMER_NO_INDEX
FOR (n:A)
on (n.CUSTOMER_NO)

And do the same with PROGRAM_CODE.

Extra tip: While Cypher lets you label nodes, relationships, and properties however you wish, the naming conventions are:
labels: LabelName (caps starting at first word)
properties: customerNo (caps starting at second word)
relationships: MY_RELATIONSHIP (all caps, underscores)

That makes it easier to understand the structure from just looking at the code. Cypher 读取 CSV,为数据集添加标签并创建索引

Hope that helps!

huangapple
  • 本文由 发表于 2023年5月18日 12:41:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76277788.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定