查看分区架构配置 - Amazon Timestream

要获得与亚马逊 Timestream 类似的功能 LiveAnalytics,可以考虑适用于 InfluxDB 的亚马逊 Timestream。适用于 InfluxDB 的 Amazon Timestream 提供简化的数据摄取和个位数毫秒级的查询响应时间,以实现实时分析。点击此处了解更多信息。

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

查看分区架构配置

可通过多种方式查看表配置如何对架构进行分区。在控制台中,选择数据库,然后选择要查看的表。您也可以使用 SDK 以访问 DescribeTable 操作。

描述具有分区键的表

可使用以下代码段,描述具有分区键的表。

Java
public void describeTable() { System.out.println("Describing table"); final DescribeTableRequest describeTableRequest = new DescribeTableRequest(); describeTableRequest.setDatabaseName(DATABASE_NAME); describeTableRequest.setTableName(TABLE_NAME); try { DescribeTableResult result = amazonTimestreamWrite.describeTable(describeTableRequest); String tableId = result.getTable().getArn(); System.out.println("Table " + TABLE_NAME + " has id " + tableId); // If table is created with composite partition key, it can be described with // System.out.println(result.getTable().getSchema().getCompositePartitionKey()); } catch (final Exception e) { System.out.println("Table " + TABLE_NAME + " doesn't exist = " + e); throw e; } }

下面是一个示例输出。

  1. 表包含维度类型分区键

    [{Type: DIMENSION,Name: hostId,EnforcementInRecord: OPTIONAL}]
  2. 表包含度量名称类型分区键

    [{Type: MEASURE,}]
  3. 从未指定复合分区键的已创建表中获取复合分区键

    [{Type: MEASURE,}]
Java v2
public void describeTable() { System.out.println("Describing table"); final DescribeTableRequest describeTableRequest = DescribeTableRequest.builder() .databaseName(DATABASE_NAME).tableName(TABLE_NAME).build(); try { DescribeTableResponse response = writeClient.describeTable(describeTableRequest); String tableId = response.table().arn(); System.out.println("Table " + TABLE_NAME + " has id " + tableId); // If table is created with composite partition key, it can be described with // System.out.println(response.table().schema().compositePartitionKey()); } catch (final Exception e) { System.out.println("Table " + TABLE_NAME + " doesn't exist = " + e); throw e; } }

下面是一个示例输出。

  1. 表包含维度类型分区键

    [PartitionKey(Type=DIMENSION, Name=hostId, EnforcementInRecord=OPTIONAL)]
  2. 表包含度量名称类型分区键

    [PartitionKey(Type=MEASURE)]
  3. 从未指定复合分区键的已创建表中获取复合分区键将返回

    [PartitionKey(Type=MEASURE)]
Go v1
<tablistentry> <tabname> Go </tabname> <tabcontent> <programlisting language="go"></programlisting> </tabcontent> </tablistentry>

下面是一个示例输出。

{ Table: { Arn: "arn:aws:timestream:us-west-2:533139590831:database/devops/table/host_metrics_dim_pk_1", CreationTime: 2023-05-31 01:52:00.511 +0000 UTC, DatabaseName: "devops", LastUpdatedTime: 2023-05-31 01:52:00.511 +0000 UTC, MagneticStoreWriteProperties: { EnableMagneticStoreWrites: true, MagneticStoreRejectedDataLocation: { S3Configuration: { BucketName: "timestream-sample-bucket-west", EncryptionOption: "SSE_S3", ObjectKeyPrefix: "TimeStreamCustomerSampleGo" } } }, RetentionProperties: { MagneticStoreRetentionPeriodInDays: 73000, MemoryStoreRetentionPeriodInHours: 6 }, Schema: { CompositePartitionKey: [{ EnforcementInRecord: "OPTIONAL", Name: "hostId", Type: "DIMENSION" }] }, TableName: "host_metrics_dim_pk_1", TableStatus: "ACTIVE" } }
Go v2
func (timestreamBuilder TimestreamBuilder) DescribeTable() (*timestreamwrite.DescribeTableOutput, error) { describeTableInput := &timestreamwrite.DescribeTableInput{ DatabaseName: aws.String(databaseName), TableName: aws.String(tableName), } describeTableOutput, err := timestreamBuilder.WriteSvc.DescribeTable(context.TODO(), describeTableInput) if err != nil { fmt.Printf("Failed to describe table with Error: %s", err.Error()) } else { fmt.Printf("Describe table is successful : %s\n", JsonMarshalIgnoreError(*describeTableOutput)) // If table is created with composite partition key, it will be included in the output } return describeTableOutput, err }

下面是一个示例输出。

{ "Table": { "Arn":"arn:aws:timestream:us-east-1:351861611069:database/cdpk-wr-db/table/host_metrics_dim_pk", "CreationTime":"2023-05-31T22:36:10.66Z", "DatabaseName":"cdpk-wr-db", "LastUpdatedTime":"2023-05-31T22:36:10.66Z", "MagneticStoreWriteProperties":{ "EnableMagneticStoreWrites":true, "MagneticStoreRejectedDataLocation":{ "S3Configuration":{ "BucketName":"error-configuration-sample-s3-bucket-cq8my", "EncryptionOption":"SSE_S3", "KmsKeyId":null,"ObjectKeyPrefix":null } } }, "RetentionProperties":{ "MagneticStoreRetentionPeriodInDays":73000, "MemoryStoreRetentionPeriodInHours":6 }, "Schema":{ "CompositePartitionKey":[{ "Type":"DIMENSION", "EnforcementInRecord":"OPTIONAL", "Name":"hostId" }] }, "TableName":"host_metrics_dim_pk", "TableStatus":"ACTIVE" }, "ResultMetadata":{} }
Python
def describe_table(self): print('Describing table') try: result = self.client.describe_table(DatabaseName=DATABASE_NAME, TableName=TABLE_NAME) print("Table [%s] has id [%s]" % (TABLE_NAME, result['Table']['Arn'])) # If table is created with composite partition key, it can be described with # print(result['Table']['Schema']) except self.client.exceptions.ResourceNotFoundException: print("Table doesn't exist") except Exception as err: print("Describe table failed:", err)

下面是一个示例输出。

  1. 表包含维度类型分区键

    [{'CompositePartitionKey': [{'Type': 'DIMENSION', 'Name': 'hostId', 'EnforcementInRecord': 'OPTIONAL'}]}]
  2. 表包含度量名称类型分区键

    [{'CompositePartitionKey': [{'Type': 'MEASURE'}]}]
  3. 从未指定复合分区键的已创建表中获取复合分区键

    [{'CompositePartitionKey': [{'Type': 'MEASURE'}]}]