aws / aws/aws-sdk-java-v2

TableSchema.converterForAttribute() returns wrong generic type

オープン
#3,965 コメント 3 件 リアクション 3 件 担当者 0 名 GitHub で見る
bug dynamodb-enhanced p2
主要言語
Java
スター
2.6k
フォーク
1k
平均マージ
2日 9時間
マージ済み PR(30日)
51

説明

### Describe the bug

The `TableSchema` interface has a method, `converterForAttribute(Object key)`, which returns an `AttributeConverter`. This AttributeConverter is meant to convert the attribute behind the given key. Unfortunately, the generic type here (`T`) is the type for the table record, not for the attribute.

If I have the following DynamoDbBean (non-compilable, just for explanation purposes):

```java
@DynamoDbBean
public class ShoppingCartItem{
public static final String CUSTOMER_ID_SECONDARY_INDEX_NAME = "shopping_cart_item_by_customer_id";

private UUID customerId;

@DynamoDbSecondaryPartitionKey(indexNames = CUSTOMER_ID_SECONDARY_INDEX_NAME)
public UUID getCustomerId() {
return customerId;
}
}
```

If then create a corresponding `DynamoDbTable` and try fetching the converter for the secondary partition key:

```java
DynamoDbTable table = ...;

String partitionKey = table.tableSchema().tableMetadata().indexPartitionKey(ShoppingCartItem.CUSTOMER_ID_SECONDARY_INDEX_NAME);

AttributeConverter converter = table.tableSchema().converterForAttribute(partitionKey);
```

The `AttributeConverter` returned is of type `AttributeConverter` instead of type `AttributeConverter`. This makes it impossible to use the TableSchema to fetch the corresponding AttributeConverter, because it will always return an AttributeConverter scoped to the type of the table, not of the attribute.

### Expected Behavior

`TableSchema.converterForAttribute(Object key)` should return a generic type other than `AttributeConverter` so callers can use it properly.

### Current Behavior

Described above.

### Reproduction Steps

Described above.

### Possible Solution

Change the return type of `TableSchema.converterForAttribute(Object key)`.

### Additional Information/Context

_No response_

### AWS Java SDK version used

dynamodb-enhanced-2.20.56

### JDK version used

1.8

### Operating System and version

macOS 13.3.1

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

エントリーポイントである TableSchema.converterForAttribute(Object key) から開始し、enhanced DynamoDB モジュール内でその宣言、実装、呼び出し元を追跡します。ShoppingCartItem の例に対してジェネリック契約を検証します。UUID によって裏付けられたセカンダリパーティションキーは、他の TableSchema ユーザーを壊すことなく AttributeConverter を提供する必要があります。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
aws, java
領域
backend-api-design, databases
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。