#469 - Suppress emission of null values when using simple and primitive result types.

Results projected onto simple and primitive types that are null are no longer emitted.

A SQL query SELECT MAX(age) FROM my_table that returns a SQL NULL and that would be consumed as Long.class (Publisher<Long>) is an example for a primitive type that can be null. Since Reactive Streams prohibits the propagation of null values by a Publisher to a Subscriber the only viable option is to suppress null results by wrapping the mapping function into Optional result values and filter these values later to avoid null being emitted.
This commit is contained in:
Mark Paluch
2020-10-02 10:47:32 +02:00
parent 7a094b6765
commit c3cb70f5ec
6 changed files with 122 additions and 3 deletions

View File

@@ -104,7 +104,25 @@ public class R2dbcEntityTemplateUnitTests {
assertThat(statement.getBindings()).hasSize(1).containsEntry(0, Parameter.from("Walter"));
}
@Test // gh-220
@Test // gh-469
public void shouldProjectExistsResult() {
MockRowMetadata metadata = MockRowMetadata.builder()
.columnMetadata(MockColumnMetadata.builder().name("name").build()).build();
MockResult result = MockResult.builder().rowMetadata(metadata)
.row(MockRow.builder().identified(0, Object.class, null).build()).build();
recorder.addStubbing(s -> s.startsWith("SELECT"), result);
entityTemplate.select(Person.class) //
.as(Integer.class) //
.matching(Query.empty().columns("MAX(age)")) //
.all() //
.as(StepVerifier::create) //
.verifyComplete();
}
@Test // gh-469
public void shouldExistsByCriteria() {
MockRowMetadata metadata = MockRowMetadata.builder()

View File

@@ -92,6 +92,11 @@ public class H2R2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIn
return H2LegoSetRepository.class;
}
@Test // gh-469
public void shouldSuppressNullValues() {
repository.findMax("doo").as(StepVerifier::create).verifyComplete();
}
@Test // gh-235
public void shouldReturnUpdateCount() {
@@ -139,6 +144,9 @@ public class H2R2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIn
interface H2LegoSetRepository extends LegoSetRepository {
@Query("SELECT MAX(manual) FROM legoset WHERE name = :name")
Mono<Integer> findMax(String name);
@Override
@Query("SELECT name FROM legoset")
Flux<Named> findAsProjection();