谁能告诉我 UpdateTableSpec 是否只能更新 KeySchema 属性,是否有任何方法可以更新/修改具有非 keyschema 属性的表?我的场景是:我创建了一个带有复合键的表,其中包含主键(#id 属性)和范围键(#Name 属性)。现在我想添加第三个属性,性别,它不是 keyschema 的一部分。这可能吗?
我正在使用以下代码更新我的 DynamoDB 表,但它没有添加性别属性,尽管它成功更新了预置属性:
static void updateTable() {
System.out.println("Updating the table with new attributes ...");
Table table = dynamoDB.getTable(tableName);
UpdateTableSpec updateTableSpec = new UpdateTableSpec();
List<AttributeDefinition> attributeDefinitionList = updateTableSpec.getAttributeDefinitions();
if (null == attributeDefinitionList) {
attributeDefinitionList = new ArrayList<AttributeDefinition>();
}
attributeDefinitionList.add(new AttributeDefinition()
.withAttributeName("Gender")
.withAttributeType("S"));
updateTableSpec.withAttributeDefinitions(attributeDefinitionList)
.withProvisionedThroughput(new ProvisionedThroughput()
.withReadCapacityUnits(6L)
.withWriteCapacityUnits(7L));;
table.updateTable(updateTableSpec);
try {
table.waitForActive();
System.out.println("Table updated succesfully");
} catch (final Exception ex) {
System.out.println("Exception occurred while updating the table");
}
}
最佳答案
您无法更新 DynamoDB 表的键架构。更新表 API 只能用于(来自 doc ):
- Modify the provisioned throughput settings of the table.
- Enable or disable Streams on the table.
- Remove a global secondary index from the table.
- Create a new global secondary index on the table. Once the index begins backfilling, you can use UpdateTable to perform other operations.
我认为,您最好的选择是迁移到具有所需新 key 架构的新表。您可以看到其他选项here .
关于java - dynamoDB 表上的 UpdateTableSpec 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41662233/