第一步
在hive-site.xml文件中配置zookeeper,hive通过这参数的配置去连接HBase
<property> <name>hbase.zookeeper.quorum</name> <value>node1,node2,node3</value> </property>
第二步
将HBase中的9个包拷贝到hive/lib目录下
scp hbase-client-1.2.0-cdh5.9.3.jar hbase-common-1.2.0-cdh5.9.3.jar hbase-hadoop2-compat-1.2.0-cdh5.9.3.jar hbase-hadoop-compat-1.2.0-cdh5.9.3.jar hbase-it-1.2.0-cdh5.9.3.jar hbase-protocol-1.2.0-cdh5.9.3.jar hbase-server-1.2.0-cdh5.9.3.jar high-scale-lib-1.1.1.jar htrace-core-3.2.0-incubating.jar /opt/Hadoop/hive/lib
第三步
创建与HBase集成的Hive的外部表
hive (default)> CREATE EXTERNAL TABLE weblogs( > id string, > datatime string, > userid string, > searchname string, > retorder string, > cliorder string, > cliurl string > ) > STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' > WITH SERDEPROPERTIES ( > "hbase.columns.mapping" = > ":key,info:datatime,info:userid,info:searchname,info:retorder,info:cliorder,info:cliurl") > TBLPROPERTIES ("hbase.table.name" = "weblogs"); OK Time taken: 1.267 seconds
CREATE EXTERNAL TABLE weblogs(id string,datatime string,userid string,searchname string,retorder string,cliorder string,cliurl string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:datatime,info:userid,info:searchname,info:retorder,info:cliorder,info:cliurl") TBLPROPERTIES ("hbase.table.name" = "weblogs");