このトピックでは、Python 用 Tablestore SDK を使用してテーブルの情報をクエリする方法について説明します。
前提条件
クライアントが初期化されていること。 詳細については、「Tablestore クライアントを初期化する」をご参照ください。
メソッド
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)