aws / aws/aws-sdk-java-v2

Dynamic specification of index name on @DynamoDbSecondaryPartitionKey annotation

Aperta
#6,253 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
dynamodb-enhanced feature-request needs-triage
Lingua principale
Java
Stelle
2.6k
Fork
1k
Merge medio
2g 9h
PR unite (30g)
51

Descrizione

### Describe the feature

Provide the ability to dynamically specify the name of the index when using the @DynamoDbSecondaryPartitionKey which today only allows for static definition of the index name.

### Use Case

I need to be able to dynamically provide the name of the index in a Spring Boot application since our index names have an environment name component to them. Currently the @DynamoDbSecondaryPartitionKey annotation requires a static name of the index so this is not possible.

### Proposed Solution

Establish a new DynamoDbSecondaryIndexNameProvider interface and update the annotation to accept a static name or any implementing class of DynamoDbSecondaryIndexNameProvider so the name can be determined at runtime.

**Domain Object**
```
@DyanmoDbBean
public class DomainObject {

@DynamoDbPartitionKey
@DynamoDbAttribute("key")
private String key;

@DynamoDbAttribute("secondary_index_key")
@DynamoDbSecondaryPartitionKey(indexNames = "secondary_index_gsi")
private String secondaryIndexKey;
}
```

**Interface for index name provider**
Default implementation acts as a passthrough which provides current behavior of annotation
```
public interface IndexNameResolver {
default String getIndexName(String indexStaticName) {
return indexStaticName;
}
}
```

**User defined implementation**
```
@Service
public class DynamicIndexNameResolverImpl implements IndexNameResolver {

@Autowired
private Environment environment;

@Override
public String getIndexName(final String indexStaticName) {
/*
* user defined logic for deriving the actual index name from the static value provided in the annotation
* essentially treating the value as a lookup key instead of the actual name.
*/
}
}
```

**User defined Spring bean configuration**
```
@Bean
public DynamoDbEnhancedClient dynamoDbEnhancedClient(final DynamoDbClient dynamoDbClient, final IndexNameResolver indexNameResolver) {
return DynamoDbEnhancedClient.builder()
.dynamoDbClient(dynamoDbClient)
.indexNameResolver(indexNameResolver) // Enhanced client would be modified to accept the custom resolver implementation
.build();
}
```

### Other Information

_No response_

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### AWS Java SDK version used

2.31.77

### JDK version used

21

### Operating System and version

macOS Sequoia 15.5

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia tracciando come Enhanced Client utilizza gli indexNames di @DynamoDbSecondaryPartitionKey e dove è definita la configurazione del builder di DynamoDbEnhancedClient. Valuta l’interfaccia del provider proposta e la sua interazione con i metadati delle annotazioni e la costruzione del client. Il lavoro è completato quando i chiamanti possono fornire un resolver che ricava i nomi degli indici a runtime, mantenendo al contempo il supporto per il comportamento esistente con nomi statici.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
aws, java
Ambito
database
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.