spring-data-couchbase icon indicating copy to clipboard operation
spring-data-couchbase copied to clipboard

Count queries field name requirement regression [DATACOUCH-649]

Open spring-projects-issues opened this issue 5 years ago • 1 comments

Eduard Dudar opened DATACOUCH-649 and commented

With Spring Data Couchbase 3.x I had a few custom counting queries written like

@Query("SELECT COUNT(*) FROM ... WHERE ...")

but upon upgrading to 4.x the same code fails with #block terminated with an error and an error being NPE in mapper. While inspecting closer what's going on, I can see that ReactiveFindByQueryOperationSupport.count() has this mapping operation

row -> row.getLong(TemplateUtils.SELECT_COUNT)

and expects a field named count but Couchbase returns $1: 0. Changing queries to

@Query("SELECT COUNT(*) AS count FROM ... WHERE ...")

works but I haven't found any requirement in the docs for this and it is working with 3.x so I feel like this is a regression


No further details from DATACOUCH-649

spring-projects-issues avatar Nov 12 '20 00:11 spring-projects-issues

Michael Reiche commented

Hi Eduard Dudar - Your analysis appears to be correct. In 3.2 there is a test in 

org.springframework.data.couchbase.repository.N1qlCrudRepositoryIntegrationTests.

shouldCustomCountWhenReturningLongAndUsingStringWithoutSpEL()

that did not get carried forward. 

spring-projects-issues avatar Nov 13 '20 01:11 spring-projects-issues

It just gets the first one now:

row.getLong(row.getNames().iterator().next())

mikereiche avatar May 10 '23 18:05 mikereiche