本文介紹如何通過 Java SDK 更新表的配置資訊。
前提條件
方法說明
public UpdateTableResponse updateTable(UpdateTableRequest request) throws TableStoreException, ClientException
範例程式碼
以下範例程式碼用於修改test_table表的配置資訊。
public static void updateTableExample(SyncClient client) {
UpdateTableRequest request = new UpdateTableRequest("test_table");
// 設定預留讀為0CU,預留寫為0CU
ReservedThroughput reservedThroughput = new ReservedThroughput(0, 0);
request.setReservedThroughputForUpdate(reservedThroughput);
TableOptions tableOptions = new TableOptions();
// 設定最大版本數
tableOptions.setMaxVersions(3);
// 設定資料生命週期,單位為秒
tableOptions.setTimeToLive(86400);
// 設定有效版本偏差,單位為秒
tableOptions.setMaxTimeDeviation(86400);
// 設定是否允許更新
tableOptions.setAllowUpdate(false);
request.setTableOptionsForUpdate(tableOptions);
// 開啟Stream資訊,並設定Stream到期時間為7天
StreamSpecification streamSpecification = new StreamSpecification(true, 168);
request.setStreamSpecification(streamSpecification);
// 調用updateTable方法修改表配置
client.updateTable(request);
}