spring-data-dynamodb icon indicating copy to clipboard operation
spring-data-dynamodb copied to clipboard

findAllByAttributeStartingWith requires @EnableScan even when attribute is a GSI Hash Key

Open parxier opened this issue 7 years ago • 4 comments
trafficstars

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

  1. Add GSI Hash Key attribute:
    @DynamoDBIndexHashKey(globalSecondaryIndexName = "AttributeIndex")
    @DynamoDBAttribute
    private String attribute;
  1. Add repository method:
List<Entity> findAllByAttributeStartingWith(String attributePrefix);
  1. Executing that method causes IllegalArgumentException asking for @EnableScan annotation.

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 avatar May 05 '18 03:05 parxier

@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.

AWS link

derjust avatar May 13 '18 18:05 derjust

Tested:

  • List<Entity> findAllByAttributeStartingWith(String attributePrefix); FAILS with Scanning for this query is not enabled
  • List<Entity> findByAttributeStartingWith(String attributePrefix); FAILS with Scanning for this query is not enabled
  • Optional<Entity> findByAttributeStartingWith(String attributePrefix); FAILS with Scanning for this query is not enabled
  • Entity findByAttributeStartingWith(String attributePrefix); FAILS with Scanning for this query is not enabled

Hope this helps.

parxier avatar May 14 '18 02:05 parxier

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)

engrun avatar Jun 25 '18 08:06 engrun

@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.

rogeriofbrito avatar May 17 '19 21:05 rogeriofbrito