derjust / spring-data-dynamodb

This module deals with enhanced support for a data access layer built on AWS DynamoDB.
https://derjust.github.io/spring-data-dynamodb/
Apache License 2.0
403 stars 141 forks source link

Same hash for multiple GSI, how to fetch data? #298

Open bg-orhanocak opened 1 year ago

bg-orhanocak commented 1 year ago

I have a main Player table and two gsi tables demonstrated below:

Player

Partition Key - PlayerId Attribute - ScoreType1 Attribute - ScoreType2 Attribute - IsoCountryCode

GSI-1

Partition Key - Country Sort Key - ScoreType1 Attribute - PlayerId

GSI-2

Partition Key Country Sort Key ScoreType2 Attribute PlayerId

I wrote entity class by giving both GSI's names into globalSecondaryIndexNames ,

@DynamoDBTable(tableName = "Player")
    public class PlayerDynamoEntity {
    @DynamoDBHashKey(attributeName = "PlayerId")
    private String player;

    @DynamoDBAttribute(attributeName = "CountryCode")
    @DynamoDBIndexHashKey(attributeName = "CountryCode",
            globalSecondaryIndexNames = {"GSI-1", "GSI-2"})
    private String countryCode;

    @DynamoDBAttribute(attributeName = "Score-1")
    @DynamoDBIndexRangeKey(attributeName = "Score-1", globalSecondaryIndexName = "GSI-1")
    private String score1;

    @DynamoDBAttribute(attributeName = "Score-2")
    @DynamoDBIndexRangeKey(attributeName = "Score-2", globalSecondaryIndexName = "GSI-2")
    private String score2;

and repository:

@EnableScan
public interface PlayerRepository extends CrudRepository<PlayerDynamoEntity, String> {
    Page<PlayerDynamoEntity> findByCountryCode(String countryCode, Pageable pageable);
}

Hence the countryCode is the hash for both GSI tables, Whenever I write ***ByCountryCode it automatically behaves like I only query for GSI-1. How can I access to second GSI table?

I expected to specify the GSI somehow but I couldn't find it.