DynamoDB batchWrite, different hash key, same range key. but got Provided list of item keys contains duplicates

huangapple go评论93阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年3月10日 07:10:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75690884.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定