microsoft / spring-data-cosmosdb

Access data with Azure Cosmos DB
MIT License
94 stars 64 forks source link

unsupported keyword: GREATER_THAN (1): [IsGreaterThan, GreaterThan] #347

Closed ggthename closed 4 years ago

ggthename commented 5 years ago

I'm using Spring JPA + cosmos db.

public interface DeviceTelemetryRepository extends DocumentDbRepository<DeviceTelemetry, String>{

    List<DeviceTelemetry> findAll();

    @Query(value="SELECT * FROM DeviceTelemetry where deviceId= ?1 and date >= ?2 and date <= ?3", nativeQuery = true)
    List<DeviceTelemetry> findDeviceTelemetryByDeviceIdAndDateGreaterThanAndDateLessThan(@Param("deviceId") int deviceId,
                                                               @Param("from") long from,
                                                               @Param("to") long to    );

}
java.lang.IllegalArgumentException: unsupported keyword: GREATER_THAN (1): [IsGreaterThan, GreaterThan]
    at com.microsoft.azure.spring.data.documentdb.repository.query.DocumentDbQueryCreator.from(DocumentDbQueryCreator.java:82) ~[spring-data-cosmosdb-2.0.3.jar:na]
    at com.microsoft.azure.spring.data.documentdb.repository.query.DocumentDbQueryCreator.and(DocumentDbQueryCreator.java:56) ~[spring-data-cosmosdb-2.0.3.jar:na]
    at com.microsoft.azure.spring.data.documentdb.repository.query.DocumentDbQueryCreator.and(DocumentDbQueryCreator.java:25) ~[spring-data-cosmosdb-2.0.3.jar:na]
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:122) ~[spring-data-commons-2.0.10.RELEASE.jar:2.0.10.RELEASE]
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:95) ~[spring-data-commons-2.0.10.RELEASE.jar:2.0.10.RELEASE]
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:81) ~[spring-data-commons-2.0.10.RELEASE.jar:2.0.10.RELEASE]
    at com.microsoft.azure.spring.data.documentdb.repository.query.PartTreeDocumentDbQuery.createQuery(PartTreeDocumentDbQuery.java:38) ~[spring-data-cosmosdb-2.0.3.jar:na]
    at com.microsoft.azure.spring.data.documentdb.repository.query.AbstractDocumentDbQuery.execute(AbstractDocumentDbQuery.java:25) ~[spring-data-cosmosdb-2.0.3.jar:na]

Do you have any plan to add GREATER_THAN or BETWEEN ? If you have alternative way to avoid this exception, please let me know.

Thank you!

sophiaso commented 5 years ago

@ggthename Thanks for filing issue, according to your stack trace, seems you are using version 2.0.3, if you are using Spring Boot 2.0.x, try upgrading to 2.0.6.

ggthename commented 5 years ago

@sophiaso Thank you for your response. I'm using azure-documentdb-spring-boot-starter 2.0.4 It has spring-data-cosmosdb-2.0.3 And azure-documentdb-spring-boot-starter 2.0.5 that has spring-data-cosmosdb-2.0.4 is the latest version.

you mean I need to add 2.0.6 manually. right? But I think it doesn't have compatibility for azure-documentdb-spring-boot-starter 2.0.5

Correct the classpath of your application so that it contains a single, compatible version of com.microsoft.azure.spring.data.cosmosdb.DocumentDbFactory

===================================================== when I use azure-documentdb-spring-boot-starter 2.0.5, "GreaterThan" is working. But the same column is not supported. (e.g. a<=?1 and a>=?2)

com.microsoft.azure.documentdb.DocumentClientException: Message: {"Errors":["Invalid query. Specified duplicate parameter name '@date'."]}

Please let me know, How can I use "Between crateria" Thank you!

sophiaso commented 5 years ago

@ggthename You can use the azure-cosmosdb-spring-boot-starter(not azure-documentdb-spring-boot-starter) version 2.0.13, which uses spring-data-cosmosdb 2.0.6. Between should have been supported in 2.0.6, check this issue. Also you can reference the integration tests in this repo for the usage.

ggthename commented 5 years ago

@sophiaso Thank you! It works. I think that it should be modified. Azure Cosmos DB Starter

Because many people who want to use Azure Cosmos DB can access this page easily. Can you explain the details? What is the difference between azure-cosmosdb-spring-boot-starter and azure-documentdb-spring-boot-starter

sophiaso commented 5 years ago

As the previous azure documentdb brand has been renamed to azure cosmosdb, so the starters and spring-data-cosmosdb is renamed. So please use the new starter azure-cosmosdb-spring-boot-starter, thanks.