使用 Python 仅从 Cloud Big Table 获取行键?

Fetching only the row-keys from Cloud Big Table using Python?

Java HBase 库支持一种特殊的过滤器,它只从 BT 获取行键。是否可以对 Python 做同样的事情?最好使用 google 的库 - https://github.com/googleapis/python-bigtable

Java: https://cloud.google.com/bigtable/docs/hbase-client/javadoc/com/google/cloud/bigtable/hbase/adapters/filters/KeyOnlyFilterAdapter

没有使用 python 库的此类过滤器,因为它可用于 HBase 库以仅获取 Bigtable 中的行键。但是你仍然可以通过对'filter_modify_strip_value(project_id, instance_id, table_id)'函数做一些修改来检索行键,你可以从this github link. Please use this function only when there is a need to count the number of rows or only the row-keys are needed as the function uses the StripValue filter 用空字符串替换每个单元格的值,但行键仍然存在。您可以尝试使用以下代码:

from google.cloud import bigtable
import datetime
import google.cloud.bigtable.row_filters as row_filters
 
def filter_modify_strip_value(project_id="my_project_id", instance_id="my-instance-id", table_id="my-table-name"):
   print("---- filter_modify_strip_value ----")
   client = bigtable.Client(project=project_id, admin=True)
   instance = client.instance(instance_id)
   table = instance.table(table_id)
 
   rows = table.read_rows(
       filter_=row_filters.StripValueTransformerFilter(True))
      
   for row in rows:
       print(row.row_key.decode('utf-8'))
 
filter_modify_strip_value()