项目作者: SakhriHoussem

项目描述 :
Learn How Hive Work With HBase in Simple Example
高级语言:
项目地址: git://github.com/SakhriHoussem/HBase-With-Hive.git
创建时间: 2017-12-29T15:50:00Z
项目社区:https://github.com/SakhriHoussem/HBase-With-Hive

开源协议:

下载


HBase With Hive

Learn How Hive Work With HBase in Simple Example

We will import DATA from ‘Hiking’ TABLE created on HBase.

  1. # Hive startup commande
  2. hive
  1. # show TABLES in Hive
  2. SHOW TABLES;
  1. # Hive shutdown
  2. exit

Create HBase TABLE ‘hiking’ :

The syntax to Create TABLE :

  1. CREATE EXTERNAL TABLE table_name(key String, col1 string, col2 int...)
  2. STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
  3. WITH SERDEPROPERTIES("hbase.columns.mapping"=":key,columnFamily:colx...") #columnFamily:col in HBase
  4. TBLPROPERTIES("hbase.table.name"="table_name"); #TABLE in HBase

Example :

For each family column in HBase, We will create TABLE in Hive

  1. # import and create external table InfoTechnique
  2. CREATE EXTERNAL TABLE InfoTechnique(key int,distance float, Altitude int)
  3. STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
  4. WITH SERDEPROPERTIES("hbase.columns.mapping"=":key,infoTechnique:distance,infoTechnique:Altitude")
  5. TBLPROPERTIES("hbase.table.name"="hiking");
  1. # import and create external table InfoTechnique
  2. CREATE EXTERNAL TABLE infoHiking(key INT,name STRING, region STRING, suiteHiking INT)
  3. STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
  4. WITH SERDEPROPERTIES("hbase.columns.mapping"=":key,infoHiking:name,infoHiking:region,infoHiking:suiteHiking")
  5. TBLPROPERTIES ("hbase.table.name" = "hiking");

Queries :

get from TABLE hiking 4 :

  1. SELECT info.key ,info.name ,info.region, tech.distance, tech.Altitude, info.suiteHiking
  2. FROM InfoTechnique tech
  3. FULL JOIN InfoHiking info ON (tech.key = info.key)
  4. WHERE info.key=4;

get InfoHiking of hiking 5 :

  1. SELECT key, name, region, suiteHiking
  2. FROM InfoHiking info
  3. WHERE key=5;

get the distance of the hiking ‘Murdjadu Mountain’ :

  1. SELECT tech.distance
  2. FROM InfoTechnique tech FULL
  3. JOIN InfoHiking info ON (tech.key = info.key)
  4. WHERE info.name='Montagne de Murdjadju';

get the distance of the hiking in the region of ‘Tizi Ouzou’ :

  1. SELECT tech.distance FROM InfoTechnique tech
  2. FULL JOIN InfoHiking info ON (tech.key = info.key)
  3. WHERE info.region='Tizi Ouzou';