Hive和Hbase整合

  • 整合hbase和hive:

              1. 在hive-site.xml里面添加:

          

                   hive.aux.jars.path

                   file:///usr/lib/hive/lib/hive-hbase-handler-0.9.0-cdh4.1.0.jar,file:///usr/lib/hbase/hbase-0.94.2-cdh4.2.0-security.jar,file:///usr/lib/zookeeper/zookeeper.jar

          

          

                    hbase.zookeeper.quorum

                    SVR2368HP360,SVR2369HP360,SVR2370HP360

          

2. 创建hive里面对应hbase的表(相当于hive对hbase的视图):

             CREATE EXTERNAL TABLE test_sqoop(

                 a string,

                 b string,

                 c string,

                 x string,

                 y string

             )       

             STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' 

             WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf:b,cf:c,cf:x,cf:y") 

             TBLPROPERTIES("hbase.table.name" = "test_sqoop");

 

  • 导hive数据

           1. 创建hive avro文件格式表

        CREATE TABLE test_avro

        ROW FORMAT

        SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'

        STORED AS

        INPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'

        OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'

        TBLPROPERTIES ('avro.schema.literal'='{  

        "namespace": "testing.hive.avro.serde",  

        "name": "test_avro",  

        "type": "record",  

        "fields": [   

{ "name":"a",      

        "type":"string",      

        "doc":"test a"},    

        {  "name":"b",      

        "type":"string",      

        "doc":"test b"},    

        {"name":"c",      

        "type":"string",      

        "doc":"test c"},    

        {"name":"x",      

        "type":"string",      

        "doc":"test d"},

        {"name":"y",      

        "type":"string",      

        "doc:":"test e",      

        "default":"fishfingers and custard" } 

]}');

2. hbase导入到hive:

           insert overwrite table test_avro select * from test_sqoop;

你可能感兴趣的:(hadoop)