Home > OS >  Neo4J - Is there a way to load multiple subqueries like LOAD ... CREATE .. LOAD .. CREATE .. LOAD ..
Neo4J - Is there a way to load multiple subqueries like LOAD ... CREATE .. LOAD .. CREATE .. LOAD ..

Time:06-15

So I'm trying to get one general database sheet for default. In MySQL, I can delete the whole database and run my code to generate the default database again. e.g. the only document for MySQL -> wwfsaew.sql

DROP DATABASE IF EXISTS wwfsaew;
CREATE DATABASE IF NOT EXISTS wwfsaew;

CREATE TABLE Flughafen (...)
...
INSERT INTO Flughafen (...)
...
UPDATE Flughafen SET ...
...
CREATE VIEW ...
...
CREATE PROCEDURE ...
...

But the same in Neo4J doesn't work. I always get the Error message: "Neo.TransientError.General.OutOfMemoryError"

LOAD CSV WITH HEADERS FROM
'file:///C:/Users/Enes/CSV_import/ingredients.csv'
    AS a
LOAD CSV WITH HEADERS FROM 
'file:///C:/Users/Enes/CSV_import/users.csv'
    AS b FIELDTERMINATOR ';'
        LOAD CSV WITH HEADERS FROM 
'file:///C:/Users/Enes/CSV_import/recipes.csv'
    AS c FIELDTERMINATOR ';'

CREATE (ing:ingredients{name:a.ingredientName,
    ingredientName:a.ingredientName})
CREATE (use:users{
    name:b.userName,
    userName:b.userName,
    userEmail:b.userEmail,
    userPassword:b.userPassword,
    enabled:b.enabled})
CREATE (rec:recipe{
    name:c.recipeName,
    recipeName:c.recipeName,
    prepTimeInMin: c.prepTimeInMin,
    restTimeInMinutes: c.restTimeInMinutes,
    prepText: c.prepText,
    people: c.people,
    viewCount: c.viewCount,
    difficultyName: c.difficultyName,
    mealTypeName: c.mealTimeName,
    createdByUser: c.createdByUser})

I don't have an idea why it doesn't work like this because every subquery for its own is ~20ms. I tried it with USING PERIODIC COMMIT 250 but then it throws a Semantic Error because it is an explicit transaction instead of an implicit one. So my question is: How can I get only one .cypher or.csv file to run it in Neo4J to get the default GraphDatabase.

CodePudding user response:

Your query throws an OutOfMemoryError because you are trying to import 3 csv together, and in this way the total number of rows will be the Cartesian product of the three CSVs. That is, if you have 3 csv with 50 rows, you'll receive from the first load csv 50 results, for each result with the 2nd load csv 50 result, and for each result with the 3rd one 50 results. Therefore you will have 50x50x50 result. Try importing one csv at a time, with the USING PERIODIC COMMIT NNN in case, that is:

LOAD CSV WITH HEADERS FROM
'file:///C:/Users/Enes/CSV_import/ingredients.csv'
    AS a
CREATE (ing:ingredients{name:a.ingredientName,
    ingredientName:a.ingredientName})
LOAD CSV WITH HEADERS FROM 
'file:///C:/Users/Enes/CSV_import/users.csv'
    AS b FIELDTERMINATOR ';'
CREATE (use:users{
    name:b.userName,
    userName:b.userName,
    userEmail:b.userEmail,
    userPassword:b.userPassword,
    enabled:b.enabled})
LOAD CSV WITH HEADERS FROM 
'file:///C:/Users/Enes/CSV_import/recipes.csv'
    AS c FIELDTERMINATOR ';'
CREATE (rec:recipe{
    name:c.recipeName,
    recipeName:c.recipeName,
    prepTimeInMin: c.prepTimeInMin,
    restTimeInMinutes: c.restTimeInMinutes,
    prepText: c.prepText,
    people: c.people,
    viewCount: c.viewCount,
    difficultyName: c.difficultyName,
    mealTypeName: c.mealTimeName,
    createdByUser: c.createdByUser})

EDIT:

:auto USING PERIODIC COMMIT 200
LOAD CSV WITH HEADERS FROM
'file:///ingredients.csv'
    AS a
CREATE (ing:ingredients{name:a.ingredientName,
    ingredientName:a.ingredientName})

with 1 as ignored limit 1

LOAD CSV WITH HEADERS FROM 
'file:///users.csv'
    AS b FIELDTERMINATOR ';'
CREATE (use:users{
    name:b.userName,
    userName:b.userName,
    userEmail:b.userEmail,
    userPassword:b.userPassword,
    enabled:b.enabled})

with 1 as ignored limit 1

LOAD CSV WITH HEADERS FROM 
'file:///recipes.csv'
    AS c FIELDTERMINATOR ';'

CREATE (rec:recipe{
    name:c.recipeName,
    recipeName:c.recipeName,
    prepTimeInMin: c.prepTimeInMin,
    restTimeInMinutes: c.restTimeInMinutes,
    prepText: c.prepText,
    people: c.people,
    viewCount: c.viewCount,
    difficultyName: c.difficultyName,
    mealTypeName: c.mealTimeName,
    createdByUser: c.createdByUser})

return 1 limit 1
  • Related