How to scan for a particular column value by rowkey and cell in Hbase?

414 Views Asked by At

I am very new to Hbase, I have an HBase table with several columns (hebe_30, hebe_31 etc.,) and where code+date is the row key.

I have the data as below

  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

How do I get the record by code+date+cell in Python? Such as 000330-20180131-hebe_30, I don't know which filter to use? Is there any CASE WHEN, WHERE OR HAVING methods like SQL query in Hbase? Below python code can scan one record by code+date, I have to let the atune:hebe_30 be the default parameter, but what we need is 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}}

Thanks so much for any advice

1

There are 1 best solutions below

0
Lyashko Kirill On

You can use ColumnPrefixFilter
I guess that in python it looks like:

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