I would like to do the following:
- Export a part of my production database to file (e.g. sub-graph/query)
- Import this file into a test database fixture which is used for testing my user defined procedure.
I'm failing at step 2 (import) because the method withFixture() in Neo4jConfigurator does not allow multistatement cypher files to be loaded. I used apoc.export.cypher.query to export the data. I have not found any option to export the query to cypher file using only single statements. I have also tested exporting with apoc.export.cypher.graph.
I'd imagine creating tests based on bugs found in production to be a somewhat common pattern. If anyone knows how to do this, please let me know.
I use 'withFixture' with files that have many lines of cypher. Can you upload an example to look at and the code that has 'withFixture'?
To load the data, I use the neo4j procedure template as is: GitHub - neo4j-examples/neo4j-procedure-template: Boilerplate code for building Procedures for Neo4j 3.0+
The issue seems to be in the structure of the cypher file generated by APOC.
In order to not leak any sensitive data, I've taken the first two lines and anonymized them:
CREATE INDEX FOR (node:NodeType1) ON (node.node_attr_1);
CREATE INDEX FOR (node:NodeType1) ON (node.node_attr_2);
This on its own gives the issue:
"org.neo4j.graphdb.QueryExecutionException: Expected exactly one statement per query but got: 2"
In the full example, these lines are followed by a constraint and then the unwind create pattern. To reiterate, this is with no modifications, straight from APOC export to file.
I've also already tried a few tips online like removing the semi-colon at the end of each line but new issues prop up like reuse of the same variables and such.
I played around with it. I see what you mean. I got the same error. This is what I observed:
- You can't have multiple statements in a cypher executed with "withFixture." The cypher can contain multiple lines. It just can't have multiple statements separated by ';'
- The "CREATE INDEX" command can't be part of a multiline statement; it has be run in isolation. This was true for 'withFixture' and Neo4j Browser.
- Cypher executed with 'withFixture' has to be a single cypher expression.
The only solution I found to work was to create three separate cypher files, one for each CREATE INDEX command and a 3rd for the cypher to create my data. You execute them with three 'withFixture' calls when building your in memory neo4j instance.
Thanks, for the help. That makes it a bit tricky to work with on large production data unfortunately. I think I'll have to deep dive into the issue and construct my own graph that mimics the bug with as few nodes as possible. Perhaps that's for the best anyways.
For issue completion's sake (if someone has this problem too), I should mention that the cypher file will work if you load it into a production neo4j instance that you set up via docker or install on OS. It's not a solution for testability, but it's good enough for finding the bug.
It may be a bug in the cypher parser that doesn’t correctly understand terminating the ‘create index’ command, so it isn’t possible to have any subsequent commands following.