Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #4243: Cherry pick of Fix performance for runFile (#4251) #4286

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 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,41 @@ 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});

Loading