如何使用CSV字段在LOAD语句中定义节点标签 [英] How to use a CSV field to define the node label in a LOAD statement

查看:114
本文介绍了如何使用CSV字段在LOAD语句中定义节点标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此示例摘自 https://neo4j.com/开发人员/指南导入数据和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});

我想要做的是使用CSV文件中的字段在节点中定义标签.例如:

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 });

推荐答案

您应该看看 APOC 过程.在这种情况下,有一个过程可以根据.csv文件中的列值动态创建节点.语法为:

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

这篇关于如何使用CSV字段在LOAD语句中定义节点标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆