FuzzyAmi
FuzzyAmi

Reputation: 8119

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

the Java HBase lib supports a special kind of filter that fetches only the row-keys from BT. Is it possible to do the same with Python? Preferably with google's lib - https://github.com/googleapis/python-bigtable

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

Upvotes: 0

Views: 1484

Answers (1)

Prabir
Prabir

Reputation: 1586

There is no such filter using the python library as it is available for the HBase library to fetch only the row-keys in Bigtable. But still you can retrieve the row-keys by doing some modification to the ‘filter_modify_strip_value(project_id, instance_id, table_id)’ function, which you can find from 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 which replaces the value of each cell with an empty string but the row-keys are still there. You can try with the following code :

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()

Upvotes: 4

Related Questions