【问题标题】:How to scan for a particular column value by rowkey and cell in Hbase?如何通过 Hbase 中的行键和单元格扫描特定列值?
【发布时间】:2020-03-18 01:54:31
【问题描述】:

我对 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

如何在 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}}

非常感谢您的建议

【问题讨论】:

标签: python database filter hbase database-scan


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 2014-02-04
    • 1970-01-01
    相关资源
    最近更新 更多