Skip to content

Commit 185c73d

Browse files
committed
Fix null $current error in MethodCall when using string methods in LET clauses
When executing SQL queries with LET variables containing UNIONALL and string method calls (e.g., .replace()), $current can be null while targetObjects is a non-Identifiable/non-Result value. Added an else-if branch to handle null val by passing null Identifiable to Expression.execute(), preventing the CommandExecutionException. https://claude.ai/code/session_019HJhUeYmAHEL2wx5monhz9
1 parent 64eb57e commit 185c73d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

engine/src/main/java/com/arcadedb/query/sql/parser/MethodCall.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ private Object execute(final Object targetObjects, final CommandContext context,
9797
paramValues.add(expr.execute(identifiable, context));
9898
} else if (targetObjects instanceof Result result) {
9999
paramValues.add(expr.execute(result, context));
100+
} else if (val == null) {
101+
paramValues.add(expr.execute((Identifiable) null, context));
100102
} else {
101103
throw new CommandExecutionException("Invalid value for $current: " + val);
102104
}

engine/src/test/java/com/arcadedb/function/sql/sql/SQLFunctionsTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,39 @@ void querySplit() {
608608
}
609609
}
610610

611+
@Test
612+
void queryUnionAllWithLetAndStringMethods() {
613+
database.getSchema().createDocumentType("NER");
614+
database.getSchema().createDocumentType("THEME");
615+
database.transaction(() -> {
616+
database.newDocument("NER").set("identity", "Hello World").save();
617+
database.newDocument("NER").set("identity", "Hello\nWorld").save();
618+
database.newDocument("THEME").set("identity", "Hello World Theme").save();
619+
});
620+
621+
final Map<String, Object> params = new HashMap<>();
622+
params.put("keyWordIdentifier_0", "Hello");
623+
params.put("keyWordIdentifier_1", "World");
624+
625+
final ResultSet result = database.query("sql",
626+
"SELECT expand($c) LET "
627+
+ "$a = (SELECT identity, @rid as id FROM NER "
628+
+ "WHERE identity.replace('\\n', ' ').replace('\\t', ' ').replace(' ', ' ') ILIKE ('%' + :keyWordIdentifier_0 + '%') "
629+
+ "AND identity.replace('\\n', ' ').replace('\\t', ' ').replace(' ', ' ') ILIKE ('%' + :keyWordIdentifier_1 + '%')), "
630+
+ "$b = (SELECT identity, @rid as id FROM THEME "
631+
+ "WHERE identity.replace('\\n', ' ').replace('\\t', ' ').replace(' ', ' ') ILIKE ('%' + :keyWordIdentifier_0 + '%') "
632+
+ "AND identity.replace('\\n', ' ').replace('\\t', ' ').replace(' ', ' ') ILIKE ('%' + :keyWordIdentifier_1 + '%')), "
633+
+ "$c = UNIONALL($a, $b)",
634+
params);
635+
636+
final List<Result> results = result.stream().collect(Collectors.toList());
637+
assertThat(results).hasSize(3);
638+
for (final Result r : results) {
639+
assertThat(r.hasProperty("identity")).isTrue();
640+
assertThat(r.hasProperty("id")).isTrue();
641+
}
642+
}
643+
611644
@Test
612645
void CheckAllFunctions() {
613646
final DefaultSQLFunctionFactory fFactory = ((SQLQueryEngine) database.getQueryEngine("sql")).getFunctionFactory();

0 commit comments

Comments
 (0)