使用Python仅从云大表中获取行键?

2024-10-03 04:25:12 发布

您现在位置:Python中文网/ 问答频道 /正文

JavaHBase库支持一种特殊的过滤器,它只从BT获取行键。用Python也可以这样做吗?最好使用谷歌的lib-https://github.com/googleapis/python-bigtable

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


Tags: httpsgithubcomclientcloud过滤器docslib
1条回答
网友
1楼 · 发布于 2024-10-03 04:25:12

没有使用python库的过滤器,因为HBase库只能获取Bigtable中的行键。但是您仍然可以通过修改“filter\u modify\u strip\u value(project\u id,instance\u id,table\u id)”函数来检索行键,您可以从this github link中找到该函数。仅当需要计算行数或仅需要行键时,请使用此函数,因为该函数使用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()

相关问题 更多 >