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

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

Open
bg-orhanocak opened this issue Oct 27, 2023 · 0 comments
Open

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

bg-orhanocak opened this issue Oct 27, 2023 · 0 comments

Comments

@bg-orhanocak
Copy link

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.

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

1 participant