全部产品
Search
文档中心

Tablestore:Mengambil informasi tabel

更新时间:Jul 06, 2025

Topik ini menjelaskan cara mengambil informasi tabel menggunakan Tablestore SDK for Python.

Prasyarat

Klien harus diinisialisasi terlebih dahulu. Untuk detail lebih lanjut, lihat Inisialisasi Klien Tablestore.

Metode

def describe_table(self, table_name)

Deskripsi Parameter table_name

table_name (wajib) str: Nama tabel data.

Kode contoh

Berikut adalah contoh kode untuk mengambil informasi tabel test_table.

try:
    response = client.describe_table('test_table')

    # Dapatkan informasi skema tabel.
    table_meta = response.table_meta
    print("* Nama tabel: %s" % table_meta.table_name)
    print("* Informasi kunci primer")
    for primary_key in table_meta.schema_of_primary_key:
        print(primary_key)
    print("* Informasi kolom yang telah ditentukan")
    for defined_column in table_meta.defined_columns:
        print(defined_column)

    # Dapatkan informasi konfigurasi tabel.
    table_options = response.table_options
    print("* Informasi konfigurasi tabel")
    print("Versi maksimum: %s" % table_options.max_version)
    print("Waktu hidup: %s" % table_options.time_to_live)
    print("Offset versi maksimum: %s" % table_options.max_time_deviation)
    print("Apakah memperbolehkan pembaruan: %s" % table_options.allow_update)

    # Dapatkan throughput baca/tulis yang dicadangkan untuk tabel.
    reserved_throughput_details = response.reserved_throughput_details
    print("* Throughput baca/tulis yang dicadangkan")
    print("Throughput baca yang dicadangkan: %s" % reserved_throughput_details.capacity_unit.read)
    print("Throughput tulis yang dicadangkan: %s" % reserved_throughput_details.capacity_unit.write)

    # Dapatkan informasi indeks sekunder.
    for index_meta in response.secondary_indexes:
        print("* Nama indeks sekunder: %s" % index_meta.index_name)
        print("Kolom kunci primer: %s" % index_meta.primary_key_names)
        print("Kolom yang telah ditentukan: %s" % index_meta.defined_column_names)
        print("Tipe indeks sekunder: %s" % SecondaryIndexType(index_meta.index_type).name)
except Exception as e:
    print("pengambilan informasi tabel gagal. %s" % e)

Referensi

Mengambil Informasi Tabel Deret Waktu