Neo4j CSV文件加载空单元格

时间:2017-04-05 15:17:39

标签: csv neo4j cypher

我正在将一个基本的CSV文件加载到Neo4j数据库中,该数据库有两列 - “name”和“property”。 name列始终具有值,“property”列可以具有值或空格。我想将值与“property1”关系联系起来。

我正在使用此代码:

LOAD CSV WITH HEADERS FROM 'file:///fileName.csv' AS line
MERGE (Test_Document:A {name: line.name})
WITH line, Test_Document 
FOREACH (x IN CASE WHEN line.property IS NULL THEN [] ELSE [1] END |
  MERGE (Properties:B {property1: line.property})
WITH Test_Document, Properties
FOREACH (y IN CASE WHEN Properties IS NULL THEN [] ELSE [1] END |
  MERGE (Test_Document)-[:property1]->(Properties))

我收到一条错误消息:

Unexpected end of input: expected whitespace, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL, RETURN or ')' (line 8, column 54 (offset: 423))
"  MERGE (Test_Document)-[:property1]->(Properties))"

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:3)

您的查询存在两个问题:

  1. 在第5行丢失了一个关闭的人员
  2. Properties不在第二个FOREACH的范围内,因为它是在前一个FOREACH中声明的(在FOREACH中声明的别名仅限于FOREACH范围内1}}子句)
  3. 试试这个:

    LOAD CSV WITH HEADERS FROM 'file:///fileName.csv' AS line
    MERGE (Test_Document:A {name: line.name})
    WITH line, Test_Document 
    FOREACH (x IN CASE WHEN line.property IS NULL THEN [] ELSE [1] END |
      MERGE (Properties:B {property1: line.property})
      MERGE (Test_Document)-[:property1]->(Properties)
    )
    

答案 1 :(得分:3)

另一种方法是使用<!DOCTYPE html> <html lang="en" ng-app="myApp" class="no-js"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Merchant Demo App</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/normalize.css"> <link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/main.css"> <link rel="stylesheet" type="text/css" href="lib/bootstrap.css"> <link rel="stylesheet" href="app.css"> <script src="bower_components/html5-boilerplate/dist/js/vendor/modernizr-2.8.3.min.js"></script> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" /> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" /> <script type="text/javascript" src="lib/jquery-3.2.0.js"></script> <script src="lib/bootstrap.js"></script> </head> <body> <nav class="navbar navbar-default"> <div class="container"> <div class="navbar-header"> <a class="navbar-brand" href="/"><img src="img/logo.png"/></a> </div> <ul class="nav navbar-nav navbar-right"> <li><a ui-sref="viewDashboard"><i class="fa fa-tachometer"></i>Dashboard</a></li> <li><a ui-sref="viewAboutus"><i class="fa fa-shield"></i>AboutUs</a></li> <li><a ui-sref="viewForm"><i class="fa fa-comment"></i>Form</a></li> <li><a ui-sref="viewReport"><i class="fa fa-shield"></i>Report</a></li> </ul> </div> </nav> <div ui-view></div> <footer class="footer navbar-fixed-bottom text-center"> <h5>© 1994-2017 Mastercard. Mastercard is an Equal Opportunity Employer.</h5> </footer> </body> <script src="bower_components/angular/angular.js"></script> <script src="bower_components/angular-route/angular-route.js"></script> <script src="bower_components/angular/angular-resource.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.4.2/angular-ui-router.js"></script> <script src="app.js"></script> <script src="viewDashboard/viewDashboard.js"></script> <script src="viewAboutus/viewAboutus.js"></script> <script src="viewForm/viewForm.js"></script> <script src="viewReport/viewReport.js"></script> <script src="components/version/version.js"></script> <script src="components/version/version-directive.js"></script> <script src="components/version/interpolate-filter.js"></script> </html> Controller: Report.js angular.module('myApp') .controller('reportController', function ($scope, reportCandidate) { getRecord(); function getRecord() { reportCandidate.getRecord() .success(function (response) { $scope.candidateInfo = response; //this.candidateInfo = response; }) .error(function (error) { $scope.status = 'Unable to load candidate data: ' + error.message; }); } }) .factory('reportCandidate', ['$resource', function ($resource) { var urlBase = 'http://localhost:3000/records'; var reportCandidate = {}; reportCandidate.getRecord = function () { return $resource('http://localhost:3000/records', {});; }; return reportCandidate; }]); 仅在没有缺失值时才创建关系:

 Uncaught TypeError: angular.module(...).info is not a function
    at angular-resource.js:445
    at angular-resource.js:858
(anonymous) @ angular-resource.js:445
(anonymous) @ angular-resource.js:858
angular.js:14199 Error: [$injector:unpr] Unknown provider: $resourceProvider <- $resource <- reportCandidate
http://errors.angularjs.org/1.5.11/$injector/unpr?p0=%24resourceProvider%20%3C-%20%24resource%20%3C-%20reportCandidate
    at http://localhost:8000/bower_components/angular/angular.js:68:12
    at http://localhost:8000/bower_components/angular/angular.js:4563:19
    at Object.getService [as get] (http://localhost:8000/bower_components/angular/angular.js:4716:32)
    at http://localhost:8000/bower_components/angular/angular.js:4568:45
    at getService (http://localhost:8000/bower_components/angular/angular.js:4716:32)
    at injectionArgs (http://localhost:8000/bower_components/angular/angular.js:4741:58)
    at Object.invoke (http://localhost:8000/bower_components/angular/angular.js:4763:18)
    at Object.enforcedReturnValue [as $get] (http://localhost:8000/bower_components/angular/angular.js:4609:37)
    at Object.invoke (http://localhost:8000/bower_components/angular/angular.js:4771:19)
    at http://localhost:8000/bower_components/angular/angular.js:4569:37 <div ui-view="" class="ng-scope">

仅当属性字段不为空时才会创建链接和B节点。