Skip to content

Commit

Permalink
Fixes #4243: Cherry pick of Fix performance for runFile
Browse files Browse the repository at this point in the history
  • Loading branch information
vga91 committed Nov 26, 2024
1 parent 7c6254a commit 4bdf478
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
39 changes: 28 additions & 11 deletions extended/src/main/java/apoc/cypher/CypherExtended.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,25 +193,42 @@ private void runDataStatementsInTx(Scanner scanner, BlockingQueue<RowResult> 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;
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions extended/src/test/java/apoc/cypher/CypherExtendedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion extended/src/test/resources/wrong_statements.cypher
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CREATE (n:Person{id:1);
CREATE INDEX node_id_idx FOR (n:Node) ON (n.id
CREATE (n:Person{id:1);
CREATE (n:Person{id:1});
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CREATE (n:Fail {foo: 1});
CREATE (n:Fail {foo: 2});

0 comments on commit 4bdf478

Please sign in to comment.