是否可通过API获取Amazon Timestream的表架构?
如何通过编程方式获取Amazon Timestream表的架构
Amazon Timestream没有直接返回表完整架构的专属API,但可以通过查询系统信息表来获取已生成的字段和度量类型信息,这和控制台展示的架构逻辑完全一致。
两种核心查询方式
1. 获取所有列(维度、度量、时间列)的详细信息
通过查询information_schema.columns系统表,能拿到表中所有已存在的列名、数据类型、是否可空等关键信息:
SELECT column_name, data_type, is_nullable, column_type FROM information_schema.columns WHERE database_name = '你的数据库名' AND table_name = '你的表名'
2. 仅获取度量相关的架构信息
如果只关注度量字段(而非维度或时间列),可以查询information_schema.measures系统表,它会返回每个度量的数据类型、是否为多值等细节:
SELECT measure_name, data_type, multi_value FROM information_schema.measures WHERE database_name = '你的数据库名' AND table_name = '你的表名'
用AWS SDK执行查询的示例(以Python boto3为例)
import boto3 # 初始化Timestream Query客户端 client = boto3.client('timestream-query') # 替换为你的数据库和表名 query = """ SELECT column_name, data_type FROM information_schema.columns WHERE database_name = 'my-db' AND table_name = 'my-table' """ # 执行查询并解析结果 response = client.query(QueryString=query) for row in response['Rows']: column_name = row['Data'][0]['ScalarValue'] data_type = row['Data'][1]['ScalarValue'] print(f"列名: {column_name}, 数据类型: {data_type}")
注意事项
- 确保执行查询的IAM实体拥有
timestream:Query权限,以及对应数据库和表的访问权限 - 架构是动态生成的,查询结果会随新数据写入自动更新,正好可以用来验证写入的度量类型是否一致
- 如果表中还没有写入任何数据,这些系统表会返回空结果
内容的提问来源于stack exchange,提问作者Arne Claassen
相关产品推荐
相关产品推荐

