1

I am new to Neo4j. I tried to create "Account" nodes and "Trade_History" relations at the same time using apoc.import.csv.

CALL apoc.import.csv(
            [{fileName: "file:///Account.csv", labels: ['Account']}],
            [{fileName: "file:///Trade_History.csv", type: 'TRANSACTION'}],
            {}
)

However, I received the following error message.

Neo.ClientError.Procedure.ProcedureCallFailed Failed to invoke procedure apoc.import.csv: Caused by: java.lang.IllegalStateException: Node for id space __CSV_DEFAULT_IDSPACE and id xxxxxxx not found

I think the error is that the id "xxxxxxx" is not found, but which id, Account or Trade_History, is missing? Is there an ID that exists in Trade_History that does not exist in Account? If so, is it possible to implement any way to skip (not create a relationship) if the Trade_History ID pair does not exist in the Account? Or, If you know of another candidate query, it would be appreciated.

This might be basic, but could you tell me some advice? Thank you in advance.


P.S. The first three lines of Account.csv and Trade_History.csv are as follows;

Account.csv

:ID,name
000000000080,James
000000000056,Kevin
000000000039,Thomas

Trade_History.csv

LABEL:STRING,ACCOUT:START_ID,ACCOUT:END_ID
XYZ36417771,AAA_20670095845, 047316281
XYZ56315967,BBB_0000970982, 456317783746
XYZ61489917,CCC_00209200036399,093891638
newbie
  • 19
  • 4
  • 1
    Can you share the first few lines of each csv file (including the headers) and do they conform to the [input tool format?](https://neo4j.com/docs/operations-manual/current/tools/neo4j-admin/neo4j-admin-import/#import-tool-header-format/) It might be easier to use [`LOAD CSV`](https://neo4j.com/docs/getting-started/current/data-import/csv-import/#import-load-csv) – William Lyon Mar 10 '23 at 15:50
  • Dear William Lyon Thank you very much for your reply. Additional corrections have been added to the text. I think these are conform to the input format, please let me know if I am incorrect. Also, you are right that LOAD_CSV makes data loading easier. However, in this case, the size of Account.csv and Trade_History.csv is very large and I would like to use other queries instead of LOAD_CSV.I would appreciate your advice. – newbie Mar 10 '23 at 18:03

2 Answers2

1

For the Neo4j import tool if you can set the --skip-bad-relationships flag then I think those rows will be ignored. From looking at the apoc.import.csv docs it's not clear if apoc.import.csv supports skip-bad-relationships. You could try passing {skipBadRelationships: True} in the config object, otherwise the neo4j-admin CLI can be used to set the --skip-bad-relationships flag.

See this section of the docs for more info: https://neo4j.com/docs/operations-manual/current/tutorial/neo4j-admin-import/#_skip_relationships_referring_to_missing_nodes

William Lyon
  • 8,371
  • 1
  • 17
  • 22
1

Your IllegalStateException occurs because "xxxxxxx" occurs as a value in either the :START_ID or :START_ID column in your relationships file Trade_History.csv. Ideally, you should cleanse your data before you do an import. For example:

  • If your node ID values are supposed to be numeric strings, verify that the :START_ID or :START_ID values are all numeric strings. For each violation, figure out how to fix the data or remove that row.
  • Remove extraneous spaces (like the one at the start of " 047316281"). That can be another cause of errors in CSV files.

Another observation is that you are using the syntax for defining ID spaces in your relationship file, whereas ID spaces can only be defined in a node file. That is, your relationship file is not supposed to have "ACCOUT" in ACCOUT:START_ID and ACCOUT:END_ID (it does not cause an error, but the bad syntax should be fixed to avoid confusion and possible future issues). If you really need ID spaces (and you wouldn't if you only have one node file), then you should read and follow the documentation.

cybersam
  • 63,203
  • 6
  • 53
  • 76