Hive Query Over Hbase

Hive Query Over Hbase

Hive Query Over Hbase-

1- Launch the hbase shell-

hbase shell

2- Create employee table with column family ‘cf’-

create ’employees’, ‘cf’

3- Load the sample data in employees table-

put ’employees’,’1001′,’cf:name’,’mike’

put ’employees’,’1001′,’cf:country’,’USA’

put ’employees’,’1002′,’cf:name’,’sky’

put ’employees’,’1002′,’cf:country’,’Canada’

put ’employees’,’1003′,’cf:name’,’sara’

put ’employees’,’1003′,’cf:country’,’aus’

4- Launch the hive cli & run below query-

CREATE EXTERNAL TABLE hbase_employee(key STRING, name STRING,country STRING)

STORED BY ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler’

WITH SERDEPROPERTIES (“hbase.columns.mapping” = “:key,cf:name,cf:country”)

TBLPROPERTIES (“hbase.table.name” = “employees”);

5- Test query on Hive-

select country,count(*) from hbase_employee group by country;

In case you get Hbase classes Not found exception then add hbase jar to hiv aux path-

hive –auxpath ${HBASE_HOME}/hbase-0.94.13.jar

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.