Gunakan Python SDK untuk membaca satu baris data dari tabel Tablestore.
Usage notes
Saat membaca data, Anda harus menyediakan nilai kunci utama lengkap, termasuk nilai kolom kunci utama auto-increment apa pun.
Prerequisites
Method
def get_row(self, table_name, primary_key, columns_to_get=None,
column_filter=None, max_version=1, time_range=None,
start_column=None, end_column=None, token=None,
transaction_id=None):
Examples
Contoh berikut membaca satu baris dengan nilai kunci utama row1.
try:
# Construct the primary key.
primary_key = [('id', 'row1')]
# Call the get_row method to read the row data.
consumed, return_row, next_token = client.get_row('test_table', primary_key)
print('Read CU Cost: %s' % consumed.read)
print('Write CU Cost: %s' % consumed.write)
print('Row Data: %s %s' % (return_row.primary_key, return_row.attribute_columns))
except Exception as e:
print("Get row failed with error: %s" % e)
-
Untuk mengembalikan hanya data dalam rentang versi tertentu, tentukan parameter
time_range.# Set the version range for the query to the last 24 hours. time_range = (int(time.time() * 1000 - 86400 * 1000), int(time.time() * 1000)) # Call the get_row method to read the row data. consumed, return_row, next_token = client.get_row('test_table', primary_key, time_range=time_range) -
Untuk mengambil kolom atribut tertentu, tentukan parameter
columns_to_get.columns_to_get = ['col2'] # Call the get_row method to read the row data. consumed, return_row, next_token = client.get_row('test_table', primary_key, columns_to_get=columns_to_get)