From 4bdf478e6f28586aaf7062b0392a032245bd7be8 Mon Sep 17 00:00:00 2001 From: vga91 Date: Tue, 26 Nov 2024 15:32:17 +0100 Subject: [PATCH] Fixes #4243: Cherry pick of Fix performance for runFile --- .../main/java/apoc/cypher/CypherExtended.java | 39 +++++++++++++------ .../java/apoc/cypher/CypherExtendedTest.java | 4 +- .../test/resources/wrong_statements.cypher | 4 +- .../resources/wrong_statements_runtime.cypher | 1 + 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/extended/src/main/java/apoc/cypher/CypherExtended.java b/extended/src/main/java/apoc/cypher/CypherExtended.java index dd424de076..539da4e8fa 100644 --- a/extended/src/main/java/apoc/cypher/CypherExtended.java +++ b/extended/src/main/java/apoc/cypher/CypherExtended.java @@ -193,25 +193,42 @@ private void runDataStatementsInTx(Scanner scanner, BlockingQueue que } if (!schemaOperation) { + // Periodic operations cannot be schema operations, so no need to check that here (will fail as invalid + // query) if (isPeriodicOperation(stmt)) { - Util.inThread(pools , () -> { + Util.inThread(pools, () -> { try { - return db.executeTransactionally(stmt, params, result -> consumeResult(result, queue, addStatistics, tx, fileName)); + return db.executeTransactionally( + stmt, params, result -> consumeResult(result, queue, addStatistics, tx, fileName)); } catch (Exception e) { collectError(queue, reportError, e, fileName); return null; } }); - } - else { - Util.inTx(db, pools, threadTx -> { - try (Result result = threadTx.execute(stmt, params)) { - return consumeResult(result, queue, addStatistics, tx, fileName); - } catch (Exception e) { - collectError(queue, reportError, e, fileName); - return null; + } else { + AtomicBoolean isSchemaError = new AtomicBoolean(false); + try { + Util.inTx(db, pools, threadTx -> { + try (Result result = threadTx.execute(stmt, params)) { + return consumeResult(result, queue, addStatistics, tx, fileName); + } catch (Exception e) { + // APOC historically skips schema operations + if (!(e.getMessage().contains("Schema operations on database") + && e.getMessage().contains("are not allowed"))) { + collectError(queue, reportError, e, fileName); + return null; + } + isSchemaError.set(true); + return null; + } + }); + } catch (Exception e) { + // An error thrown by a schema operation + if (isSchemaError.get()) { + continue; } - }); + throw e; + } } } } diff --git a/extended/src/test/java/apoc/cypher/CypherExtendedTest.java b/extended/src/test/java/apoc/cypher/CypherExtendedTest.java index 87f50d83fb..25d80b0b42 100644 --- a/extended/src/test/java/apoc/cypher/CypherExtendedTest.java +++ b/extended/src/test/java/apoc/cypher/CypherExtendedTest.java @@ -449,7 +449,7 @@ public void testRunFileWithFailingPeriodicStatement() { public void testRunFileWithFailingExplain() { // error during CypherExtended.isSchemaOperation method String failingFile = "wrong_statements.cypher"; - String cypherError = "Invalid input ')': expected"; + String cypherError = "Invalid input 'CREATE': expected ')' or ','"; testRunFailingFileCommon(failingFile, cypherError); } @@ -597,7 +597,7 @@ public void testLongRunningRunFilesWithFailingPeriodicStatement() { public void testRunFilesWithFailingExplain() { // error during CypherExtended.isSchemaOperation method String failingFile = "wrong_statements.cypher"; - String cypherError = "Invalid input ')': expected"; + String cypherError = "Invalid input 'CREATE': expected ')' or ','"; testRunFailingFilesCommon(failingFile, cypherError); } diff --git a/extended/src/test/resources/wrong_statements.cypher b/extended/src/test/resources/wrong_statements.cypher index 7cb0b92dd8..509a895c75 100644 --- a/extended/src/test/resources/wrong_statements.cypher +++ b/extended/src/test/resources/wrong_statements.cypher @@ -1 +1,3 @@ -CREATE (n:Person{id:1); \ No newline at end of file +CREATE INDEX node_id_idx FOR (n:Node) ON (n.id +CREATE (n:Person{id:1); +CREATE (n:Person{id:1}); \ No newline at end of file diff --git a/extended/src/test/resources/wrong_statements_runtime.cypher b/extended/src/test/resources/wrong_statements_runtime.cypher index 7a8b3ddfd4..9e73fcd338 100644 --- a/extended/src/test/resources/wrong_statements_runtime.cypher +++ b/extended/src/test/resources/wrong_statements_runtime.cypher @@ -1,2 +1,3 @@ CREATE (n:Fail {foo: 1}); +CREATE (n:Fail {foo: 2});