hbase-hive整合及sqoop的安裝配置使用

從hbase中拿數據,而後整合到hbase中   

上hive官網  -- 點擊wiki--> hive hbase integation(整合) --》 注意整合的時候兩個軟件的版本要能進行整合 按照官網的要求

在整合以前須要將hive 的jar進行導入 : hive-hbase-handler-x.y.z.jar   
單節點的啓動命令
$HIVE_SRC/build/dist/bin/hive --auxpath
$HIVE_SRC/build/dist/lib/hive-hbase-handler-0.9.0.jar,
$HIVE_SRC/build/dist/lib/hbase-0.92.0.jar,
$HIVE_SRC/build/dist/lib/zookeeper-3.3.4.jar,$HIVE_SRC/build/dist/lib/guava-r09.jar
--hiveconf hbase.master=hbase.yoyodyne.com:60000
集羣的啓動命令 --至少三個集羣  
$HIVE_SRC/build/dist/bin/hive --auxpath $HIVE_SRC/build/dist/lib/hive-hbase-handler-0.9.0.jar,$HIVE_SRC/build/dist/lib/hbase-0.92.0.jar,$HIVE_SRC/build/dist/lib/zookeeper-3.3.4.jar,$HIVE_SRC/build/dist/lib/guava-r09.jar --hiveconf hbase.zookeeper.quorum=zk1.yoyodyne.com,zk2.yoyodyne.com,zk3.yoyodyne.com

--須要將hive和hbase的jar進行整合  
a)先將hbase中的jar包拷貝到hive中  
cp ./*.jar /root/apache-hive-1.2.1-bin/lib/
b)將hive的jar包拷貝到hbase 中
cp ./hive-hbase-hadler.jar   
c)在hive客戶端分別啓動habse 和 hive  啓動 沒有前後順序  
  啓動hbase   start-hbase.sh   
  啓動hive   如今服務端啓動hive服務   hive --service metastore
  而後在客戶端啓動hive  ./hive  
  在客戶端啓動hbase   hbase shell  
  將hbase的列映射到hive中
 三、在hive中建立臨時表

CREATE EXTERNAL TABLE tmp_order
(key string, id string, user_id string)  
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'  
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,order:order_id,order:user_id")  
TBLPROPERTIES ("hbase.table.name" = "t_order");

CREATE TABLE hbasetbl(key int, value string)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val")
TBLPROPERTIES ("hbase.table.name" = "xyz", "hbase.mapred.output.outputtable" = "xyz");

在hive中插入數據,數據最終會被插入到hbase中
要建立hive外部表,須要先在hbase中建立這個表,而後在hive中建立這個表


sqoop相關知識總結  
sqoop由client端直接接入hadoop,任務經過解析生成對應的mapreduce執行
安裝步驟:
一、解壓
二、配置環境變量
export SQOOP_HOME= /XX/sqoop.xx
三、添加數據庫驅動包
cp mysql-connector-java-5.1.10.jar/sqoop-install-path/lib
四、 重命名配置文件
 mv sqoop-env-template.sh sqoop-env.sh
sqoop list-databases --connect jdbc:mysql://node1:3306 -username root --password 123

sqoop import --connect  jdbc:mysql://node1:3306/test  --username root --password 123 --columns  start_ip,end_ip,country --delete-target-dir -m 1 -table test2 --target-dir /sqoop/
 
也能夠將sqoop命令放到一個文件中 再進行執行
將sqoop放置到文件中的格式
import
--connect
jdbc:mysql://node1:3306/test  
--username
root
--password
123
--columns  
start_ip,end_ip,country
--delete-target-dir
-m
1
-table
test2
--target-dir
/sqoop/

執行文件的命令: sqoop --options-file option

二、在文件中加入具體的sql執行語句
import
--connect
jdbc:mysql://node1:3306/test  
--username
root
--password
123
--delete-target-dir
-m
1
--target-dir
/sqoop/
-e select start_ip,end_ip from test2 where $CONDITIONS

執行文件的命令:sqoop --options-file option1
注: sql語句後面必須包含條件 $CONDITIONS

在hive中查詢執行的結果:

dfs-cat /sqoop/*

在hive文件條件查詢中添加配置條件  
import
--connect
jdbc:mysql://node1:3306/test  
--username
root
--password
123
--columns  
start_ip,end_ip,country
--delete-target-dir
-m
1
-table
test2
--target-dir
/sqoop/
--where
"country = 'US'"

---將mysql的數據直接導入到hive表中
import
--connect
jdbc:mysql://node1:3306/test  
--username
root
--password
123
--columns  
start_ip,end_ip,country
--delete-target-dir
-m
1
-table
test2
--hive-import
--create-hive-table
--hive-table
sqoophive

注意命令文件的書寫格式

---將hive的數據導出到mysql
export
--connect
jdbc:mysql://node1:3306/test  
--username
root
--password
123
--columns  
start_ip,end_ip,country
-m
1
--table
h_sql
--export-dir
/sqoop/

注:要將hive的數據導入到mysql中,hive文件中存儲的數據必須是具備mysql可以接受的數據格式,纔可以將數據所有的導入。


from (
 
     select
    pl, from_unixtime
    (cast(s_time/1000 as bigint),'yyyy-MM-dd') as day, u_ud,
   
      (case when count(p_url) = 1 then "pv1"
      
     when count(p_url) = 2 then "pv2"
     
      when count(p_url) = 3 then "pv3"
      
        when count(p_url) = 4 then "pv4"
      
       when count(p_url) >= 5 and count(p_url) <10 then "pv5_10"
     
       when count(p_url) >= 10 and count(p_url) <30 then "pv10_30"
      
       when count(p_url) >=30 and count(p_url) <60 then "pv30_60"  
     
       else 'pv60_plus' end) as pv
 
       from event_logs
 
      where
    en='e_pv'
    
      and p_url is not null
    
      and pl is not null
    
      and s_time >= unix_timestamp('2019-03-15','yyyy-MM-dd')*1000
    
      and s_time < unix_timestamp('2019-03-15,'yyyy-MM-dd')*1000
 
       group by
    pl, from_unixtime(cast(s_time/1000 as bigint),'yyyy-MM-dd'), u_ud

      ) as tmp

      insert overwrite table stats_view_depth_tmp
 
      select pl,day,pv,count(distinct u_ud) as ct where u_ud is not null group by pl,day,pv;

















java

相關文章
相關標籤/搜索