英文:
DynamoDB batchWrite, different hash key, same range key. but got Provided list of item keys contains duplicates
问题
我得到的表键模式如下所示:
KeySchema: []*dynamodb.KeySchemaElement{{
AttributeName: aws.String("address"),
KeyType: aws.String(dynamodb.KeyTypeHash),
}, {
AttributeName: aws.String("tx_id"),
KeyType: aws.String(dynamodb.KeyTypeRange),
}},
写入记录的代码如下所示:
for _, storeKey := range t.StoreKeys() {
mainItem["address"], err = dynamodbattribute.Marshal(storeKey)
if err != nil {
return err
}
mainTxPut := dynamodb.PutRequest{
Item: mainItem,
}
writeRequests = append(writeRequests, &dynamodb.WriteRequest{
PutRequest: &mainTxPut,
})
}
但是当使用不同的地址值,但相同的tx_id时,我得到了错误:
ValidationException: Provided list of item keys contains duplicates
因为哈希键不同,我应该使用不同的键。那么为什么DynamoDB告诉我我的键是重复的呢?
英文:
I got table key schema like this:
KeySchema: []*dynamodb.KeySchemaElement{{
AttributeName: aws.String("address"),
KeyType: aws.String(dynamodb.KeyTypeHash),
}, {
AttributeName: aws.String("tx_id"),
KeyType: aws.String(dynamodb.KeyTypeRange),
}},
write record like this:
for _, storeKey := range t.StoreKeys() {
mainItem["address"], err = dynamodbattribute.Marshal(storeKey)
if err != nil {
return err
}
mainTxPut := dynamodb.PutRequest{
Item: mainItem,
}
writeRequests = append(writeRequests, &dynamodb.WriteRequest{
PutRequest: &mainTxPut,
})
}
but when using different address value, same tx_id, i got err:
ValidationException: Provided list of item keys contains duplicates
Beacuese hashkey is different, i should be using a different key. So why dynamodb tells me that my key is duplicated?
答案1
得分: 2
我强烈建议你添加一些日志记录,以确保批处理中没有重复项。当出现异常时,只需记录该批处理以供检查。
要成为重复项,项目必须具有相同的主键。
英文:
I'd strongly encourage you to add some logging to ensure you have no duplicates in a batch. When you get an exception simply log the batch for inspection.
Items must have the same primary key to be duplicates.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论