Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,24 @@ static <T> void createCalculator(BiFunction<String, BiFunction<Number, Number, O
"contains_all",
999,
2,
stream -> containsHandler
.apply(stream, (left, data) -> data.all(val -> handleContain(left, val)))));
stream -> CastUtils
.handleFirst(stream, (first, flux) -> {
TreeSet<Object> set =
CastUtils.castCollection(first, new TreeSet<>(CompareUtils::compare));

return flux
.skip(1)
.concatMap(val -> Flux
.just(val)
.as(CastUtils::flatStream)
.map(_val -> handleContain(set, _val))
// 如果是空数组,则contains_all结果为true
.defaultIfEmpty(true))
// 参数为空,返回false
.defaultIfEmpty(false)
.all(Boolean::booleanValue);
}
)));

//select not_contains(val,'a','b','c')
addGlobal(
Expand Down
78 changes: 78 additions & 0 deletions src/test/java/org/jetlinks/reactor/ql/ReactorQLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,18 @@ void testContains() {
.expectNext(true)
.verifyComplete();

ReactorQL.builder()
.sql("select contains_any(this,?) isIn from dual")
.build()
.start(ReactorQLContext
.ofDatasource((s) -> Flux.just(Arrays.asList(1, 2, 3, 4)))
.bind(0, Collections.emptyList()))
.doOnNext(System.out::println)
.map(e -> e.asMap().get("isIn"))
.as(StepVerifier::create)
.expectNext(false)
.verifyComplete();

{
ReactorQL.builder()
.sql("select not_contains(this,?) isIn from dual")
Expand All @@ -385,6 +397,17 @@ void testContains() {
.as(StepVerifier::create)
.expectNext(false)
.verifyComplete();
ReactorQL.builder()
.sql("select not_contains(this,?) isIn from dual")
.build()
.start(ReactorQLContext
.ofDatasource((s) -> Flux.just(Arrays.asList(1, 2, 3, 4)))
.bind(0, Collections.emptyList()))
.doOnNext(System.out::println)
.map(e -> e.asMap().get("isIn"))
.as(StepVerifier::create)
.expectNext(true)
.verifyComplete();
}

{
Expand Down Expand Up @@ -493,6 +516,61 @@ void testContains() {
.verifyComplete();
}

{
Map<String, Object> map_1 = new HashMap<>();
map_1.put("a", 1);
map_1.put("b", 1);
Map<String, Object> map_2 = new HashMap<>();
map_2.put("a", 10);
map_2.put("b", 20);
Map<String, Object> map_3 = new HashMap<>();
map_3.put("a", 100);
map_3.put("b", 200);
// 参数为null时,contains_all应该返回false
ReactorQL.builder()
.sql("select contains_all(this,?) isIn from dual")
.build()
.start(ReactorQLContext
.ofDatasource((s) -> Flux
.just(Arrays.asList(map_1, map_2, map_3)))
.bind(0, null)
)
.doOnNext(System.out::println)
.map(e -> e.asMap().get("isIn"))
.as(StepVerifier::create)
.expectNext(false)
.verifyComplete();

// 不传入参数时,contains_all应该返回false
ReactorQL.builder()
.sql("select contains_all(this,?) isIn from dual")
.build()
.start(ReactorQLContext
.ofDatasource((s) -> Flux
.just(Arrays.asList(map_1, map_2, map_3)))
)
.doOnNext(System.out::println)
.map(e -> e.asMap().get("isIn"))
.as(StepVerifier::create)
.expectNext(false)
.verifyComplete();

// 参数为空数组时,contains_all应该返回false
ReactorQL.builder()
.sql("select contains_all(this,?) isIn from dual")
.build()
.start(ReactorQLContext
.ofDatasource((s) -> Flux
.just(Arrays.asList(map_1, map_2, map_3)))
.bind(0, new ArrayList<>())
)
.doOnNext(System.out::println)
.map(e -> e.asMap().get("isIn"))
.as(StepVerifier::create)
.expectNext(true)
.verifyComplete();
}

}

@Test
Expand Down