spring-data-dynamodb
spring-data-dynamodb copied to clipboard
findAllByAttributeStartingWith requires @EnableScan even when attribute is a GSI Hash Key
Expected Behavior
As per https://github.com/derjust/spring-data-dynamodb/wiki/Supported-Spring-Data-Comparison-Operators assumption is that STARTING_WITH is supported without need for a @EnableScan.
Expected Behavior is that List<Entity> findAllByAttributeStartingWith(String attributePrefix) will use GSI and not fall back to Scan.
Actual Behavior
Exception is thrown:
java.lang.IllegalArgumentException: Scanning for this query is not enabled. To enable annotate your repository method with @EnableScan, or enable scanning for all repository methods by annotating your repository interface with @EnableScan
at org.springframework.util.Assert.isTrue(Assert.java:116)
at org.socialsignin.spring.data.dynamodb.query.MultipleEntityScanExpressionQuery.assertScanEnabled(MultipleEntityScanExpressionQuery.java:41)
at org.socialsignin.spring.data.dynamodb.query.MultipleEntityScanExpressionQuery.getResultList(MultipleEntityScanExpressionQuery.java:35)
findAllByAttribute(String attribute) works as expected and returns list of entities with exact match.
Steps to Reproduce the Problem
- Add GSI Hash Key attribute:
@DynamoDBIndexHashKey(globalSecondaryIndexName = "AttributeIndex")
@DynamoDBAttribute
private String attribute;
- Add repository method:
List<Entity> findAllByAttributeStartingWith(String attributePrefix);
- Executing that method causes
IllegalArgumentExceptionasking for@EnableScanannotation.
Specifications
- Spring Data DynamoDB Version: 5.0.2 (2.0)
- Spring Data Version: 2.0.6.RELEASE
- AWS SDK Version: 1.11.312
- Java Version: 1.8.0_162 - Java HotSpot(TM) 64-Bit Server VM 25.162-b12
- Platform Details: Mac OS X 10.13.4
@parxier Have you tested it with the method signature List<Entity> findByAttributeStartingWith(String attributePrefix)?
I have to double check if findAll ignores GSIs right from the start.
Tested:
List<Entity> findAllByAttributeStartingWith(String attributePrefix);FAILS with Scanning for this query is not enabledList<Entity> findByAttributeStartingWith(String attributePrefix);FAILS with Scanning for this query is not enabledOptional<Entity> findByAttributeStartingWith(String attributePrefix);FAILS with Scanning for this query is not enabledEntity findByAttributeStartingWith(String attributePrefix);FAILS with Scanning for this query is not enabled
Hope this helps.
I think I have stumbled across a related issue.
Using the strategy for paging, I still have to annotate my findBy* methods with @EnableScan
the error is:
java.lang.IllegalArgumentException: Scanning for this query is not enabled. To enable annotate your repository method with @EnableScan, or enable scanning for all repository methods by annotating your repository interface with @EnableScan
at org.springframework.util.Assert.isTrue(Assert.java:116)
at org.socialsignin.spring.data.dynamodb.query.MultipleEntityScanExpressionQuery.assertScanEnabled(MultipleEntityScanExpressionQuery.java:41)
at org.socialsignin.spring.data.dynamodb.query.MultipleEntityScanExpressionQuery.getResultList(MultipleEntityScanExpressionQuery.java:35)
at org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQuery$PagedExecution.execute(AbstractDynamoDBQuery.java:161)
at org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQuery.execute(AbstractDynamoDBQuery.java:303)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:590)
@derjust Any update about this issue? I'm having the same trouble that @parxier reported in this issue. I'm using the version 5.1.0.