Skip to content

[BUG] Query with aggregates and GROUP BY works Azure Data Studio but generates an exception with spring-data-cosmos #43912

Open
@Blackbaud-JasonBodnar

Description

@Blackbaud-JasonBodnar

Describe the bug
The following query works in Azure Data Studio:

SELECT c.scs, c.bbid, CONCAT(c.scs, "-", c.microservice) AS scsMicroservice, COUNT(1), SUM(c.totalCharacters) FROM c WHERE c.scs != null GROUP BY c.scs, c.bbid, CONCAT(c.scs, "-", c.microservice)

But when used with @Query() on a method in a CosmosRepository it generates an exception

Exception or Stack Trace

java.lang.IllegalArgumentException: Entity is null.
	at org.springframework.util.Assert.notNull(Assert.java:172)
	at com.azure.spring.data.cosmos.core.convert.MappingCosmosConverter.readInternal(MappingCosmosConverter.java:94)
	at com.azure.spring.data.cosmos.core.convert.MappingCosmosConverter.read(MappingCosmosConverter.java:79)
	at com.azure.spring.data.cosmos.core.CosmosTemplate.toDomainObject(CosmosTemplate.java:1303)
	at com.azure.spring.data.cosmos.core.CosmosTemplate.emitOnLoadEventAndConvertToDomainObject(CosmosTemplate.java:1299)
	at com.azure.spring.data.cosmos.core.CosmosTemplate.lambda$runQuery$35(CosmosTemplate.java:1157)
	at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:106)
	at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79)
	at reactor.core.publisher.FluxFlatMap$FlatMapMain.drainLoop(FluxFlatMap.java:713)
	at reactor.core.publisher.FluxFlatMap$FlatMapMain.drain(FluxFlatMap.java:589)
	at reactor.core.publisher.FluxFlatMap$FlatMapInner.onSubscribe(FluxFlatMap.java:956)
	at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:201)
	at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:83)
	at reactor.core.publisher.Flux.subscribe(Flux.java:8642)
	at reactor.core.publisher.FluxFlatMap$FlatMapMain.onNext(FluxFlatMap.java:427)
	at reactor.core.publisher.FluxPublishOn$PublishOnSubscriber.runAsync(FluxPublishOn.java:440)
	at reactor.core.publisher.FluxPublishOn$PublishOnSubscriber.run(FluxPublishOn.java:527)
	at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:84)
	at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:37)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)
	Suppressed: java.lang.Exception: #block terminated with an error
		at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:100)
		at reactor.core.publisher.Mono.block(Mono.java:1742)
		at com.azure.spring.data.cosmos.core.CosmosTemplate.runQuery(CosmosTemplate.java:1159)
		at com.azure.spring.data.cosmos.repository.support.StringBasedCosmosQuery.execute(StringBasedCosmosQuery.java:108)
		at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:170)
		at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:158)
		at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:164)
		at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:143)
		at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
		at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:70)
		at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
		at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
		at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)

To Reproduce
Steps to reproduce the behavior:

  1. Create a ComsosRepository with an @Query() method.
  2. Call the method.

Code Snippet

@Query(value =
    "SELECT c.scs, c.bbid, CONCAT(c.scs, \"-\", c.microservice) AS scsMicroservice, COUNT(1), SUM(c.totalCharacters) FROM c WHERE c.scs != null GROUP BY c.scs, c.bbid, CONCAT(c.scs, \"-\", c.microservice)"
    )
List<Object> getStatistics();

Expected behavior
The query does not cause an excpetion.

Setup (please complete the following information):

  • Library/Libraries: com.azure:azure-spring-data-cosmos:5.14.0
  • Java version: 17
  • Frameworks: Spring Boot

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • [ X ] Bug Description Added
  • [ X ] Repro Steps Added
  • [ X ] Setup information Added

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.CosmosService AttentionWorkflow: This issue is responsible by Azure service team.cosmos-java-ecosystem-br-planningConsidered for Browmine semester planningcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions