python - 如何通过 Hbase 中的行键和单元格扫描特定列值?
问题描述
我对 Hbase 很陌生,我有一个包含几列(hebe_30、hebe_31 等)的 HBase 表,code+date
行键在哪里。
我有如下数据
ROW COLUMN+CELL
000330-20180131 column=atune:hebe_30, timestamp=1574324850676, value=3.0
000330-20180131 column=atune:hebe_31, timestamp=1574324850676, value=6.0
000330-20180201 column=atune:hebe_32, timestamp=1574324849744, value=68.0
000330-20180201 column=atune:hebe_33, timestamp=1574324849744, value=88.0
000330-20180202 column=atune:hebe_34, timestamp=1574324855557, value=330.0
如何code+date+cell
在 Python 中获取记录?例如000330-20180131-hebe_30
,我不知道该使用哪个过滤器?Hbase中有没有CASE WHEN, WHERE OR HAVING
类似SQL查询的方法?下面的python代码可以通过 扫描一条记录code+date
,我必须让atune:hebe_30
成为默认参数,但我们需要的是code+date+atune:self.hebe_**
.
import pandas as pd
from db_connect import impala, hbasecon, ATUNETABLE
class query:
def __init__(self, code='', date=''):
self.code = code
self.date = date
self.hintltable = hbasecon(table=ATUNETABLE).gettable()
def atune_hebe(self):
val_end = ''
rows_end = self.hintltable.scan(
row_start=self.code + '-' + self.date,
row_stop=self.code + '-00000000' ,
columns=['atune:hebe_30'], reverse=True, limit=1
)
for k, v in rows_end:
val_end = eval(v['atune:hebe_30'])
return {"val": {"0": val_end}}
非常感谢您的任何建议
解决方案
您可以使用ColumnPrefixFilter
我猜在 python 中它看起来像:
for k, v in table.scan(filter="ColumnPrefixFilter('your_prsifx_str')"):
print k
推荐阅读
- javascript - 这个 setTimeout 如何在 Promise 之前被调用?
- javascript - RegEx 名称首字母大写检查
- google-drive-api - 使用 Google Drive API 客户端在共享云端硬盘中共享文件夹
- android - Firebase getValue() 返回 null
- javascript - 什么是 Javascript ?操作员?
- linux - 为什么 accept() 返回 ERESTARTSYS?
- python - Python / Django - 编辑渲染输出
- windows - 在 w3wp 中识别导致 CPU 过高的模块
- shared-libraries - 如何区分同名的共享库和静态库
- r - 数据表,与不寻常的格式化表融为一体