更新分区架构配置 - Amazon Timestream
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

从2025年6月20日起,亚马逊Timestream版 LiveAnalytics 将不再向新客户开放。如果您想使用亚马逊 Timestream LiveAnalytics,请在该日期之前注册。现有客户可以继续照常使用该服务。有关更多信息,请参阅 Amazon Timestream 以了解 LiveAnalytics 可用性变更。

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

更新分区架构配置

您可以使用具有UpdateTable操作访问权限的 SDK 来更新分区架构的表配置。

使用分区键更新表

您可以使用以下代码片段使用分区键更新表。

Java
public void updateTableCompositePartitionKeyEnforcement() { System.out.println("Updating table"); UpdateTableRequest updateTableRequest = new UpdateTableRequest(); updateTableRequest.setDatabaseName(DATABASE_NAME); updateTableRequest.setTableName(TABLE_NAME); // Can update enforcement level for dimension type partition key with OPTIONAL or REQUIRED enforcement final List<PartitionKey> partitionKeyWithDimensionAndRequiredEnforcement = Collections.singletonList(new PartitionKey() .withName(COMPOSITE_PARTITION_KEY_DIM_NAME) .withType(PartitionKeyType.DIMENSION) .withEnforcementInRecord(PartitionKeyEnforcementLevel.REQUIRED)); Schema schema = new Schema(); schema.setCompositePartitionKey(partitionKeyWithDimensionAndRequiredEnforcement); updateTableRequest.withSchema(schema); writeClient.updateTable(updateTableRequest); System.out.println("Table updated");
Java v2
public void updateTableCompositePartitionKeyEnforcement() { System.out.println("Updating table"); // Can update enforcement level for dimension type partition key with OPTIONAL or REQUIRED enforcement final List<PartitionKey> partitionKeyWithDimensionAndRequiredEnforcement = Collections.singletonList(PartitionKey .builder() .name(COMPOSITE_PARTITION_KEY_DIM_NAME) .type(PartitionKeyType.DIMENSION) .enforcementInRecord(PartitionKeyEnforcementLevel.REQUIRED) .build()); final Schema schema = Schema.builder() .compositePartitionKey(partitionKeyWithDimensionAndRequiredEnforcement).build(); final UpdateTableRequest updateTableRequest = UpdateTableRequest.builder() .databaseName(DATABASE_NAME).tableName(TABLE_NAME).schema(schema).build(); writeClient.updateTable(updateTableRequest); System.out.println("Table updated");
Go v1
// Update table partition key enforcement attribute updateTableInput := &timestreamwrite.UpdateTableInput{ DatabaseName: aws.String(*databaseName), TableName: aws.String(*tableName), // Can update enforcement level for dimension type partition key with OPTIONAL or REQUIRED enforcement Schema: &timestreamwrite.Schema{ CompositePartitionKey: []*timestreamwrite.PartitionKey{ { Name: aws.String(CompositePartitionKeyDimName), EnforcementInRecord: aws.String("REQUIRED"), Type: aws.String("DIMENSION"), }, }}, } updateTableOutput, err := writeSvc.UpdateTable(updateTableInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("Update table is successful, below is the output:") fmt.Println(updateTableOutput) }
Go v2
// Update table partition key enforcement attribute updateTableInput := &timestreamwrite.UpdateTableInput{ DatabaseName: aws.String(*databaseName), TableName: aws.String(*tableName), // Can update enforcement level for dimension type partition key with OPTIONAL or REQUIRED enforcement Schema: &types.Schema{ CompositePartitionKey: []types.PartitionKey{ { Name: aws.String(CompositePartitionKeyDimName), EnforcementInRecord: types.PartitionKeyEnforcementLevelRequired, Type: types.PartitionKeyTypeDimension, }, }}, } updateTableOutput, err := timestreamBuilder.WriteSvc.UpdateTable(context.TODO(), updateTableInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("Update table is successful, below is the output:") fmt.Println(updateTableOutput) }
Python
def update_table(self): print('Updating table') try: # Can update enforcement level for dimension type partition key with OPTIONAL or REQUIRED enforcement partition_key_with_dimension_and_required_enforcement = [ { 'Type': 'DIMENSION', 'Name': COMPOSITE_PARTITION_KEY_DIM_NAME, 'EnforcementInRecord': 'REQUIRED' } ] schema = { 'CompositePartitionKey': partition_key_with_dimension_and_required_enforcement } self.client.update_table(DatabaseName=DATABASE_NAME, TableName=TABLE_NAME, Schema=schema) print('Table updated.') except Exception as err: print('Update table failed:', err)