提示:hive 1.x 与 hbase 1.x整合时,需要自己编译
hive.zookeeper.quorum
node01,node02,node03
hive.server2.enable.doAs
false
Setting this property to true will have HiveServer2 execute
Hive operations as the user making the calls to it.
注意:hive.server2.enable.doAs必须配置,否则无法使用官方推荐的hiveserver2 / beeline的方式操作,在利用HQL语句创建HBase时会出现异常,解决方案:https://blog.csdn.net/jinYwuM/article/details/83506749
由于hive与hbase通信主要是依靠hive_hbase-handler.jar工具包,因此需要将hive中的jar包拷贝到$HBASE_HOME/lib下
cp hive-hbase-handler-2.1.1.jar /export/servers/hbase-2.1.0/lib/
采用hiveserver2 / beeline的方式启动
创建Hbase表的语法介绍
# Hive中的表名test_tb
CREATE TABLE test_tb(key int, value string)
# 指定存储处理器
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
# 声明列族,列名
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val")
# hbase.table.name声明HBase表名,为可选属性默认与Hive的表名相同
# hbase.mapred.output.outputtable指定插入数据时写入的表,如果以后需要往该表插入数据就需要指定该值
TBLPROPERTIES ("hbase.table.name" = "test_tb", "hbase.mapred.output.outputtable" = "test_tb");
put 'test_tb','98','cf1:val','val_98'
put 'test_tb','99','cf1:val','val_99'
put 'test_tb','100','cf1:val','val_100'
1)、HBase表数据
2)、Hive表数据
提示:还有一种hive与hbase映射方式,Hive映射HBase中已经存在的表,即使用HQL创建hive外部表,映射HBase已存在的表,进行关联操作。
org.apache.hadoop
hadoop-client
2.7.4
org.apache.hive
hive-jdbc
2.1.1
org.apache.hbase
hbase-client
2.1.0
org.apache.hive
hive-metastore
2.1.0
package com.theone.hive;
import java.sql.*;
public class Hive_Hbase {
private static String Driver = "org.apache.hive.jdbc.HiveDriver";
private static String URL = "jdbc:hive2://192.168.17.101:10000/hivedb";
private static String name = "root";
private static String password = "123";
public static void main(String[] args) throws SQLException {
try {
Class.forName(Driver);
Connection connection = DriverManager.getConnection(URL, name, password);
Statement statement = connection.createStatement();
String sql = "select * from test_tb";
ResultSet res = statement.executeQuery(sql);
while (res.next()) {
System.out.println(res.getInt(1) + "\t==> " + res.getString(2));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}