首页 > 解决方案 > 如何通过 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}}

非常感谢您的任何建议

标签: pythondatabasefilterhbasedatabase-scan

解决方案


您可以使用ColumnPrefixFilter
我猜在 python 中它看起来像:

for k, v in table.scan(filter="ColumnPrefixFilter('your_prsifx_str')"):
    print k

推荐阅读