我对Hbase还是很陌生,我有一个HBase表,其中包含几列(hebe_30,hebe_31等,并且其中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
如何在Python中通过code+date+cell
获取记录?例如000330-20180131-hebe_30
,我不知道要使用哪个过滤器? Hbase中是否有类似SQL查询的CASE WHEN, WHERE OR HAVING
方法?下面的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