How to use a CSV field to define the node label in a LOAD statement

喜你入骨 提交于 2019-12-07 06:44:57

问题


This example is taken from https://neo4j.com/developer/guide-importing-data-and-etl/#_importing_the_data_using_cypher"

LOAD CSV WITH HEADERS FROM "file:customers.csv" AS row
    CREATE (:Customer {companyName: row.CompanyName, customerID: row.CustomerID, fax: row.Fax, phone: row.Phone});

What I want to do is use a field in the CSV file to define the label in the node. For example:

LOAD CSV WITH HEADERS FROM "FILE:///Neo4j_AttributeProvenance.csv" AS CSVLine CREATE (q:CSVLine.NodeType { NodeID:CSVLine.NodeID, SchemaName:CSVLine.SchemaName, TableName:CSVLine.TableName, DataType:CSVLine.DataType, PreviousNodeID:CSVLine.PreviousNodeID });


回答1:


You should have a look at the APOC procedures. In this case there's a procedure able to create nodes dinamically based on column values in your .csv file. The syntax is:

CALL apoc.create.node(['Label'], {key:value,…​})

In your case the simplest syntax should be:

CALL apoc.create.node(["' + CSVLine.NodeType + '"], {NodeID: "' + NodeID:CSVLine.NodeID + '", etc}) yield node


来源:https://stackoverflow.com/questions/45166907/how-to-use-a-csv-field-to-define-the-node-label-in-a-load-statement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!