Skip to content

Commit b7adf93

Browse files
authored
Bump rsql-parser version to v2.3.2. (#154)
The v2.3.2 contains notable improvement of having unary operators like `=null=` and `=notnull=`. Previously we've been forced to `company.code=notnull=''` because parser didn't allow no argument operator. With updated version it becomes possible so above query becomes `company.code=notnull=`. However, we still accept `=notnull=''` version to not break user queries, but I believe we should remove it in the future releases.
1 parent 568f25e commit b7adf93

File tree

5 files changed

+38
-51
lines changed

5 files changed

+38
-51
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ filter = "company.id>100"; //greater than
146146
filter = "company.id<100"; //less than
147147
filter = "company.id>=100"; //greater than or equal
148148
filter = "company.id<=100"; //less than or equal
149-
filter = "company.code=isnull=''"; //is null
150-
filter = "company.code=null=''"; //is null
151-
filter = "company.code=na=''"; //is null
152-
filter = "company.code=nn=''"; //is not null
153-
filter = "company.code=notnull=''"; //is not null
154-
filter = "company.code=isnotnull=''"; //is not null
149+
filter = "company.code=isnull="; //is null
150+
filter = "company.code=null="; //is null
151+
filter = "company.code=na="; //is null
152+
filter = "company.code=nn="; //is not null
153+
filter = "company.code=notnull="; //is not null
154+
filter = "company.code=isnotnull="; //is not null
155155

156156
filter = "company.code=='demo';company.id>100"; //and
157157
filter = "company.code=='demo' and company.id>100"; //and

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<spring-boot.version>3.0.0</spring-boot.version>
2727
<spring-data-releasetrain.version>2022.0.0</spring-data-releasetrain.version>
2828
<querydsl.version>4.1.4</querydsl.version>
29-
<rsql-parser.version>2.2.1</rsql-parser.version>
29+
<rsql-parser.version>2.3.2</rsql-parser.version>
3030
<lombok.version>1.18.24</lombok.version>
3131
<hamcrest.version>2.2</hamcrest.version>
3232
<h2.version>2.2.220</h2.version>

rsql-common/src/main/java/io/github/perplexhub/rsql/RSQLOperators.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.perplexhub.rsql;
22

3+
import cz.jirutka.rsql.parser.ast.Arity;
34
import java.util.Arrays;
45
import java.util.Collections;
56
import java.util.HashSet;
@@ -15,17 +16,17 @@ public class RSQLOperators {
1516
GREATER_THAN_OR_EQUAL = new ComparisonOperator("=ge=", ">="),
1617
LESS_THAN = new ComparisonOperator("=lt=", "<"),
1718
LESS_THAN_OR_EQUAL = new ComparisonOperator("=le=", "<="),
18-
IN = new ComparisonOperator("=in=", true),
19-
NOT_IN = new ComparisonOperator("=out=", true),
20-
IS_NULL = new ComparisonOperator("=na=", "=isnull=", "=null="),
21-
NOT_NULL = new ComparisonOperator("=nn=", "=notnull=", "=isnotnull="),
19+
IN = new ComparisonOperator("=in=", Arity.of(1, Integer.MAX_VALUE)),
20+
NOT_IN = new ComparisonOperator("=out=", Arity.of(1, Integer.MAX_VALUE)),
21+
IS_NULL = new ComparisonOperator(new String[]{"=na=", "=isnull=", "=null="}, Arity.of(0, 1)),
22+
NOT_NULL = new ComparisonOperator(new String[]{"=nn=", "=notnull=", "=isnotnull="}, Arity.of(0, 1)),
2223
LIKE = new ComparisonOperator("=ke=", "=like="),
2324
NOT_LIKE = new ComparisonOperator("=nk=", "=notlike="),
2425
IGNORE_CASE = new ComparisonOperator("=ic=", "=icase="),
2526
IGNORE_CASE_LIKE = new ComparisonOperator("=ik=", "=ilike="),
2627
IGNORE_CASE_NOT_LIKE = new ComparisonOperator("=ni=", "=inotlike="),
27-
BETWEEN = new ComparisonOperator("=bt=", "=between=", true),
28-
NOT_BETWEEN = new ComparisonOperator("=nb=", "=notbetween=", true);
28+
BETWEEN = new ComparisonOperator("=bt=", "=between=", Arity.nary(2)),
29+
NOT_BETWEEN = new ComparisonOperator("=nb=", "=notbetween=", Arity.nary(2));
2930

3031
private static final Set<ComparisonOperator> OPERATORS = Collections.unmodifiableSet(
3132
new HashSet<>(Arrays.asList(EQUAL, NOT_EQUAL,

rsql-jpa/src/main/java/io/github/perplexhub/rsql/RSQLJPAPredicateConverter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,12 @@ private Predicate expressionPredicate(ComparisonNode node, ResolvedExpression.Pa
303303
if (op.equals(NOT_IN)) {
304304
return expression.in(listObject).not();
305305
}
306-
if (op.equals(BETWEEN) && listObject.size() == 2
306+
if (op.equals(BETWEEN)
307307
&& listObject.get(0) instanceof Comparable comp1
308308
&& listObject.get(1) instanceof Comparable comp2) {
309309
return builder.between(expression, comp1, comp2);
310310
}
311-
if (op.equals(NOT_BETWEEN) && listObject.size() == 2 &&
311+
if (op.equals(NOT_BETWEEN) &&
312312
listObject.get(0) instanceof Comparable comp1
313313
&& listObject.get(1) instanceof Comparable comp2) {
314314
return builder.between(expression, comp1, comp2).not();

rsql-jpa/src/test/java/io/github/perplexhub/rsql/RSQLJPASupportTest.java

+22-36
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.junit.jupiter.api.BeforeEach;
2929
import org.junit.jupiter.api.Disabled;
3030
import org.junit.jupiter.api.Test;
31+
import org.junit.jupiter.params.ParameterizedTest;
32+
import org.junit.jupiter.params.provider.ValueSource;
3133
import org.springframework.beans.factory.annotation.Autowired;
3234
import org.springframework.boot.test.context.SpringBootTest;
3335
import org.springframework.data.domain.Page;
@@ -504,53 +506,37 @@ final void testNotIn() {
504506
assertThat(rsql, count, is(7L));
505507
}
506508

507-
@Test
508-
final void testIsNull() {
509-
String rsql = "name=isnull=''";
509+
@ParameterizedTest
510+
@ValueSource(strings = {
511+
"name=isnull=''",
512+
"name=isnull=",
513+
"name=null=''",
514+
"name=null=",
515+
"name=na=''",
516+
"name=na=",
517+
})
518+
final void testIsNull(String rsql) {
510519
List<Company> companys = companyRepository.findAll(toSpecification(rsql));
511520
long count = companys.size();
512-
log.info("rsql: {} -> count: {}", rsql, count);
513-
assertThat(rsql, count, is(1L));
514-
assertThat(rsql, companys.get(0).getCode(), equalTo("null"));
515-
assertThat(rsql, companys.get(0).getName(), is(nullValue()));
516-
517-
rsql = "name=null=''";
518-
companys = companyRepository.findAll(toSpecification(rsql));
519-
count = companys.size();
520-
log.info("rsql: {} -> count: {}", rsql, count);
521-
assertThat(rsql, count, is(1L));
522-
assertThat(rsql, companys.get(0).getCode(), equalTo("null"));
523-
assertThat(rsql, companys.get(0).getName(), is(nullValue()));
524521

525-
rsql = "name=na=''";
526-
companys = companyRepository.findAll(toSpecification(rsql));
527-
count = companys.size();
528-
log.info("rsql: {} -> count: {}", rsql, count);
529522
assertThat(rsql, count, is(1L));
530523
assertThat(rsql, companys.get(0).getCode(), equalTo("null"));
531524
assertThat(rsql, companys.get(0).getName(), is(nullValue()));
532525
}
533526

534-
@Test
535-
final void testIsNotNull() {
536-
String rsql = "name=isnotnull=''";
527+
@ParameterizedTest
528+
@ValueSource(strings = {
529+
"name=isnotnull=''",
530+
"name=isnotnull=",
531+
"name=notnull=''",
532+
"name=notnull=",
533+
"name=nn=''",
534+
"name=nn="
535+
})
536+
final void testIsNotNull(String rsql) {
537537
List<Company> companys = companyRepository.findAll(toSpecification(rsql));
538538
long count = companys.size();
539-
log.info("rsql: {} -> count: {}", rsql, count);
540-
assertThat(rsql, count, is(6L));
541-
assertThat(rsql, companys.get(0).getName(), is(notNullValue()));
542-
543-
rsql = "name=notnull=''";
544-
companys = companyRepository.findAll(toSpecification(rsql));
545-
count = companys.size();
546-
log.info("rsql: {} -> count: {}", rsql, count);
547-
assertThat(rsql, count, is(6L));
548-
assertThat(rsql, companys.get(0).getName(), is(notNullValue()));
549539

550-
rsql = "name=nn=''";
551-
companys = companyRepository.findAll(toSpecification(rsql));
552-
count = companys.size();
553-
log.info("rsql: {} -> count: {}", rsql, count);
554540
assertThat(rsql, count, is(6L));
555541
assertThat(rsql, companys.get(0).getName(), is(notNullValue()));
556542
}

0 commit comments

Comments
 (0)