0
任何人都可以讓我知道UpdateTableSpec是否只能更新KeySchema屬性,並且有什麼方法可以更新/修改具有非keyschema屬性的表嗎?我的場景是:我創建了一個包含主要(#id屬性)和範圍鍵(#Name屬性)的組合鍵的表。現在我想添加第三個屬性Gender,它不是keyschema的一部分。可能嗎 ?DynamoDB表上的UpdateTableSpec不起作用
我使用下面的代碼來更新我的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");
}
}