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

Ability to apply filter expressions to Query for Numbers and Boolean fields #262

Open
adarshhm6 opened this issue Mar 31, 2021 · 1 comment

Comments

@adarshhm6
Copy link

With Reference to
#27 and
https://github.com/boostchicken/spring-data-dynamodb/wiki/Change-Log

We now have an option to filter the Query Result using filterExpression as below.

With static parameters

@query(fields = "leaveDate", limit = 1, filterExpression = "contains(#field, :value)",
expressionMappingNames = {@ExpressionAttribute(key = "#field", value = "name")},
expressionMappingValues = {@ExpressionAttribute(key=":value", value = "projection")})
List findByPostCode(String postCode);

With dynamic parameters from methods

@Query(fields = "leaveDate", limit = 1, filterExpression = "contains(#field, :value)",
		expressionMappingNames = {@ExpressionAttribute(key = "#field", value = "name")},
		expressionMappingValues = {@ExpressionAttribute(key=":value", parameterName = "projection")})
List<User> findByPostCode(@Param("postCode") String postCode, @Param("projection") String projection);

But Is there any option or feature available to filter the result based on a field which is of Type Number and Boolean.
Let's say In Table I have Price column of type Number and I want to filter the final result based on Price >=100.
Then how can we achieve it with filterExpression as ExpressionAttribute has only key, value and parameterName which all are of type String.

Specifications

  • Spring Data DynamoDB Version: 5.2.5
  • Spring Data Version: 2.2.4.RELEASE
  • AWS SDK Version: 1.11.771
  • Java Version: 8
  • Platform Details: Windows 10

All those information are logged by org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactory on INFO level on startup.
Or use java -version and mvn dependency:tree | grep -E 'spring|aws' to provide those version numbers.

@adarshhm6 adarshhm6 changed the title Ability to apply filter expressions to Querys for Numbers and Boolean Type fields Ability to apply filter expressions to Query for Numbers and Boolean fields Mar 31, 2021
@dulshand
Copy link

Hello, I am trying to create a repository using @query. Below is the sample code.
@EnableScan
public interface MyCRUDRepository extends CrudRepository<Student, StudentKey> {
@query(filterExpression = "contains(#field, :value)",
expressionMappingNames = {@ExpressionAttribute(key = "#field", value = "firstName")},
expressionMappingValues = {@ExpressionAttribute(key=":value", parameterName = "firstName")})
List findList(@param("firstName") String firstName);
}
I am getting the following error:
You have defined query method in the repository but you don't have any query lookup strategy defined. The infrastructure apparently does not support query methods!

What could be the reason?

2021-07-11 15:45:34.632 INFO 30940 --- [ main] o.s.s.d.d.r.s.DynamoDBRepositoryFactory : Spring Data DynamoDB Version: 5.2.5 (2.2)
2021-07-11 15:45:34.634 INFO 30940 --- [ main] o.s.s.d.d.r.s.DynamoDBRepositoryFactory : Spring Data Version: 2.0.9.RELEASE
2021-07-11 15:45:34.635 INFO 30940 --- [ main] o.s.s.d.d.r.s.DynamoDBRepositoryFactory : AWS SDK Version: 1.11.771
2021-07-11 15:45:34.635 INFO 30940 --- [ main] o.s.s.d.d.r.s.DynamoDBRepositoryFactory : Java Version: 11.0.4 - OpenJDK 64-Bit Server VM 11.0.4+10-b304.77
2021-07-11 15:45:34.635 INFO 30940 --- [ main] o.s.s.d.d.r.s.DynamoDBRepositoryFactory : Platform Details: Windows 10 10.0
2021-07-11 15:45:34.635 WARN 30940 --- [ main] o.s.s.d.d.r.s.DynamoDBRepositoryFactory : This Spring Data DynamoDB implementation might not be compatible with the available Spring Data classes on the classpath!
NoDefClassFoundExceptions or similar might occur!
2021-07-11 15:45:34.823 WARN 30940 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dynamoDbController': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dynamoDbRepository': Unsatisfied dependency expressed through field 'myCRUDRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myCRUDRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: You have defined query method in the repository but you don't have any query lookup strategy defined. The infrastructure apparently does not support query methods!
2021-07-11 15:45:34.828 INFO 30940 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants