Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Simple query with Sort but without any where clause in @Query fails while using "ReactiveCosmosRepository" #40018

Closed
3 tasks done
SanjayDasTezpur opened this issue May 3, 2024 · 2 comments · Fixed by #40083
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@SanjayDasTezpur
Copy link

Describe the bug
A straightforward query lacking a filter condition, but including sorting, encounters failure when utilized with ReactiveCosmosRepository. An instance:

@Query(value = "SELECT * from c")
    Flux<Entity> findEntities(Sort sort);

Exception or Stack Trace

2024-05-03T12:33:57.784+05:30 ERROR 60770 --- [flexi-hierarchy] [nio-8080-exec-1] c.w.p.f.c.FlexiHierarchyController       : java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 1
java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 1
	at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4606)
	at java.base/java.lang.String.substring(String.java:2709)
	at com.azure.spring.data.cosmos.core.generator.NativeQueryGenerator.generateSortedQuery(NativeQueryGenerator.java:58)
	at com.azure.spring.data.cosmos.core.ReactiveCosmosTemplate.runQuery(ReactiveCosmosTemplate.java:900)
	at com.azure.spring.data.cosmos.repository.support.StringBasedReactiveCosmosQuery.execute(StringBasedReactiveCosmosQuery.java:102)
	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.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223)
	at jdk.proxy3/jdk.proxy3.$Proxy102.findEntities(Unknown Source)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:354)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223)
	at jdk.proxy3/jdk.proxy3.$Proxy102.findEntities(Unknown Source)

To Reproduce

  1. Create a @repository interface in Spring Boot By Extending ReactiveCosmosRepository
  2. Write a abstract method with simple query with Sort, like above mentioned method.
  3. Call this method from any service or controller.

Code Snippet
pom.xml

       <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>spring-cloud-azure-starter-data-cosmos</artifactId>
        </dependency>

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.azure.spring</groupId>
                <artifactId>spring-cloud-azure-dependencies</artifactId>
                <version>${spring-cloud-azure.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

Repository

@Repository
public interface EntityRepo extends ReactiveCosmosRepository<Entity, String> {
    @Query(value = "SELECT * from c")
    Flux<Entity> findEntities(Sort sort);

}

Controller

@Log4j2
@RestController
@RequiredArgsConstructor
public class FlexiHierarchyController {

    private final EntityRepo repo;

    @GetMapping("/all")
    public Flux<Entity> all(String sortBy, String sortOrder) {
        try {
            return repo.findEntities(Sort.by(Sort.Direction.valueOf(sortOrder), sortBy));

        } catch (Exception e) {
            log.error(e);
            e.printStackTrace();
        }
        return null;
    }

}

Expected behavior
Should return all records from database in sorted order.

Setup (please complete the following information):

  • OS: Mac OS m2
  • IDE: Intellij Ultimate
  • Library/Libraries: <spring-cloud-azure.version> 5.11.0 </spring-cloud-azure.version> , Please chcek above pom.xml to match
  • Java version: [e.g. 17]
  • App Server/Environment: Tomcat
  • 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

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels May 3, 2024
@trande4884 trande4884 self-assigned this May 3, 2024
@SanjayDasTezpur
Copy link
Author

Hi @trande4884 ,
Just FYI,
Currently I am doing a workaround to solve this problem.

@Query(value = "SELECT * from c WHERE CONTAINS(c.id, '', true) ")

@trande4884
Copy link
Member

@SanjayDasTezpur thank you for the update and I am glad you currently have a work around. I am going to start looking into this today so I should have an update for you soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants