本文介紹如何通過Python SDK查詢資料表的詳細資料。
前提條件
方法說明
def describe_table(self, table_name)範例程式碼
以下範例程式碼用於查詢test_table表的詳細資料。
try:
response = client.describe_table('test_table')
# 擷取資料表結構資訊
table_meta = response.table_meta
print("* 資料表名稱: %s" % table_meta.table_name)
print("* 主鍵資訊")
for primary_key in table_meta.schema_of_primary_key:
print(primary_key)
print("* 預定義列資訊")
for defined_column in table_meta.defined_columns:
print(defined_column)
# 擷取資料表的配置資訊
table_options = response.table_options
print("* 資料表配置資訊")
print("最大版本數: %s" % table_options.max_version)
print("資料生命週期: %s" % table_options.time_to_live)
print("有效版本偏差: %s" % table_options.max_time_deviation)
print("是否允許更新: %s" % table_options.allow_update)
# 擷取資料表預留讀寫輸送量
reserved_throughput_details = response.reserved_throughput_details
print("* 預留讀寫輸送量")
print("預留讀輸送量: %s" % reserved_throughput_details.capacity_unit.read)
print("預留寫輸送量: %s" % reserved_throughput_details.capacity_unit.write)
# 擷取二級索引資訊
for index_meta in response.secondary_indexes:
print("* 二級索引名稱: %s" % index_meta.index_name)
print("主鍵列表: %s" % index_meta.primary_key_names)
print("預定義列列表: %s" % index_meta.defined_column_names)
print("二級索引類型: %s" % SecondaryIndexType(index_meta.index_type).name)
except Exception as e:
print("describe table failed. %s" % e)