Skip to content

Commit b4ebf3f

Browse files
authored
Fixes #4243: Cherry pick of Fix performance for runFile (#4251)
1 parent b7d8a60 commit b4ebf3f

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

extended/src/main/java/apoc/cypher/CypherExtended.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,25 +193,41 @@ private void runDataStatementsInTx(Scanner scanner, BlockingQueue<RowResult> que
193193
}
194194

195195
if (!schemaOperation) {
196+
// Periodic operations cannot be schema operations, so no need to check that here (will fail as invalid query)
196197
if (isPeriodicOperation(stmt)) {
197-
Util.inThread(pools , () -> {
198+
Util.inThread(pools, () -> {
198199
try {
199-
return db.executeTransactionally(stmt, params, result -> consumeResult(result, queue, addStatistics, tx, fileName));
200+
return db.executeTransactionally(
201+
stmt, params, result -> consumeResult(result, queue, addStatistics, tx, fileName));
200202
} catch (Exception e) {
201203
collectError(queue, reportError, e, fileName);
202204
return null;
203205
}
204206
});
205-
}
206-
else {
207-
Util.inTx(db, pools, threadTx -> {
208-
try (Result result = threadTx.execute(stmt, params)) {
209-
return consumeResult(result, queue, addStatistics, tx, fileName);
210-
} catch (Exception e) {
211-
collectError(queue, reportError, e, fileName);
212-
return null;
207+
} else {
208+
AtomicBoolean isSchemaError = new AtomicBoolean(false);
209+
try {
210+
Util.inTx(db, pools, threadTx -> {
211+
try (Result result = threadTx.execute(stmt, params)) {
212+
return consumeResult(result, queue, addStatistics, tx, fileName);
213+
} catch (Exception e) {
214+
// APOC historically skips schema operations
215+
if (!(e.getMessage().contains("Schema operations on database")
216+
&& e.getMessage().contains("are not allowed"))) {
217+
collectError(queue, reportError, e, fileName);
218+
return null;
219+
}
220+
isSchemaError.set(true);
221+
return null;
222+
}
223+
});
224+
} catch (Exception e) {
225+
// An error thrown by a schema operation
226+
if (isSchemaError.get()) {
227+
continue;
213228
}
214-
});
229+
throw e;
230+
}
215231
}
216232
}
217233
}

extended/src/test/java/apoc/cypher/CypherExtendedTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public void testRunFileWithFailingPeriodicStatement() {
449449
public void testRunFileWithFailingExplain() {
450450
// error during CypherExtended.isSchemaOperation method
451451
String failingFile = "wrong_statements.cypher";
452-
String cypherError = "Invalid input ')': expected";
452+
String cypherError = "Invalid input 'CREATE': expected ')' or ','";
453453
testRunFailingFileCommon(failingFile, cypherError);
454454
}
455455

@@ -597,7 +597,7 @@ public void testLongRunningRunFilesWithFailingPeriodicStatement() {
597597
public void testRunFilesWithFailingExplain() {
598598
// error during CypherExtended.isSchemaOperation method
599599
String failingFile = "wrong_statements.cypher";
600-
String cypherError = "Invalid input ')': expected";
600+
String cypherError = "Invalid input 'CREATE': expected ')' or ','";
601601
testRunFailingFilesCommon(failingFile, cypherError);
602602
}
603603

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
CREATE (n:Person{id:1);
1+
CREATE INDEX node_id_idx FOR (n:Node) ON (n.id
2+
CREATE (n:Person{id:1);
3+
CREATE (n:Person{id:1});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
CREATE (n:Fail {foo: 1});
2+
CREATE (n:Fail {foo: 2});
23

0 commit comments

Comments
 (0)