Count queries field name requirement regression [DATACOUCH-649]
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
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.
It just gets the first one now:
row.getLong(row.getNames().iterator().next())