Skip to content

Commit 0de0c84

Browse files
fix: sql too long error occurs when ARRAY_CONTAINS's param empty (#76)
Co-authored-by: lidong <li.dong@smartcompany.jp>
1 parent 91e1396 commit 0de0c84

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.github.thunderz99</groupId>
55
<artifactId>java-cosmos</artifactId>
66
<packaging>jar</packaging>
7-
<version>0.5.20</version>
7+
<version>0.5.21</version>
88
<name>${project.groupId}:${project.artifactId}$</name>
99
<description>A lightweight Azure CosmosDB client for Java</description>
1010
<url>https://github.com/thunderz99/java-cosmos</url>

src/main/java/io/github/thunderz99/cosmos/condition/SubQueryExpression.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.microsoft.azure.documentdb.SqlQuerySpec;
55
import io.github.thunderz99.cosmos.util.Checker;
66
import io.github.thunderz99.cosmos.util.JsonUtil;
7+
import org.apache.commons.lang3.ObjectUtils;
78
import org.apache.commons.lang3.StringUtils;
89

910
import java.util.ArrayList;
@@ -167,6 +168,9 @@ static String buildArrayContainsAll(String joinKey, String filterKey, String par
167168

168169
if(paramValue instanceof Collection<?>){
169170

171+
if (ObjectUtils.isEmpty(paramValue)) {
172+
return "(1=0)";
173+
}
170174
var paramCollection = (Collection<?>) paramValue;
171175

172176
var index = 0;

src/test/java/io/github/thunderz99/cosmos/CosmosDatabaseTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,30 @@ void dynamic_field_should_work_for_ARRAY_CONTAINS_ALL() throws Exception {
12951295
assertThat(map).containsEntry("name", "Jerry");
12961296
}
12971297

1298+
{
1299+
// empty with ARRAY_CONTAINS
1300+
var cond = Condition.filter("id", id, String.format("%s.value ARRAY_CONTAINS", formId), "");
1301+
var items = db.find(coll, cond, partition).toMap();
1302+
1303+
assertThat(items).hasSize(0);
1304+
}
1305+
1306+
{
1307+
// empty list with ARRAY_CONTAINS_ANY
1308+
var cond = Condition.filter("id", id, String.format("%s.value ARRAY_CONTAINS_ANY", formId), List.of());
1309+
var items = db.find(coll, cond, partition).toMap();
1310+
1311+
assertThat(items).hasSize(0);
1312+
}
1313+
1314+
{
1315+
// empty list with ARRAY_CONTAINS_ALL
1316+
var cond = Condition.filter("id", id, String.format("%s.value ARRAY_CONTAINS_ALL", formId), List.of());
1317+
var items = db.find(coll, cond, partition).toMap();
1318+
1319+
assertThat(items).hasSize(0);
1320+
}
1321+
12981322
} finally {
12991323
db.delete(coll, id, partition);
13001324
}

0 commit comments

Comments
 (0)