使用DescribeTable介面可以查詢指定表的結構、預留讀/寫輸送量詳情等資訊。

说明 API說明請參見DescribeTable

前提條件

  • 已初始化OTSClient。更多資訊,請參見初始化
  • 已建立資料表。

介面

def describe_table(self, table_name):

返回為表的描述資訊。返回結果中describe_table_response表示表的描述資訊,是ots2.metadata.DescribeTableResponse類的執行個體。

參數

參數 說明
table_name 表名。

樣本

擷取表的描述資訊。

try:
    describe_response = ots_client.describe_table('myTable')
    # 如果沒有拋出異常,則說明執行成功,列印如下表資訊。
    print "describe table succeeded."
    print ('TableName: %s' % describe_response.table_meta.table_name)
    print ('PrimaryKey: %s' % describe_response.table_meta.schema_of_primary_key)
    print ('Reserved read throughput: %s' % describe_response.reserved_throughput_details.capacity_unit.read)
    print ('Reserved write throughput: %s' % describe_response.reserved_throughput_details.capacity_unit.write)
    print ('Last increase throughput time: %s' % describe_response.reserved_throughput_details.last_increase_time)
    print ('Last decrease throughput time: %s' % describe_response.reserved_throughput_details.last_decrease_time)
    print ('table options\'s time to live: %s' % describe_response.table_options.time_to_live)
    print ('table options\'s max version: %s' % describe_response.table_options.max_version)
    print ('table options\'s max_time_deviation: %s' % describe_response.table_options.max_time_deviation)
except Exception:
    # 如果拋出異常,則說明執行失敗,處理異常。
    print "describe table failed."
            

詳細代碼請參見DescribeTable@GitHub