hive mysql Hbase间导表方式

本文详细介绍了如何将Hive与HBase进行数据集成,包括建立关联表、导入TSV方式、bulkload方式、使用UDF及HiveServer2等方法,并通过实例演示了如何将数据从MySQL导入到Hive。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


hbase hive
1、建立hive hbase 关联表(暂时线上环境不支持,待测试)

CREATE TABLE hive_user_info(
a string,b string,c string,
d string,e string,
f string,g string)
PARTITIONED BY(dt string)
STORED BY'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES
("hbase.columns.mapping"=":key,info:b,info:c,info:d,info:e,info:e,info:f ")
TBLPROPERTIES("hbase.table.name" = "user_info");

2、importtsv 方式(不支持)
hbase org.apache.hadoop.hbase.mapreduce.ImportTsv -Dimporttsv.columns=a,b,c <tablename> <hdfs-inputdir>

3、bulkload 方式(不支持)

HTable hTable = new HTable(configuration, tableName);//指定表名
loadFfiles.doBulkLoad(new Path(pathToHFile), hTable);//导入数据, pathToHFile为hfile文件名

4、table.put()

Hive导入数据到mysql

1、sqoop

2、udf
CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
select dboutput('jdbc:mysql://10.100.56.22:3306/ddshow_stat','ucst-sys','E2xNDFT6rSecx','insert into t_temp_access_pv_log(ytId,room) values(?,?)',remain_count,remain_count_tag) from t_result_user_remain_day_stat limit 100;
ytId,room 为t_temp_access_pv_log 的字段
remain_count,remain_count_tag 为 t_result_user_remain_day_stat 的字段


3、Hive server2 (不支持)

Class.forName( "org.apache.hive.jdbc.HiveDriver");
Connection con = DriverManager.getConnection(
"jdbc:hive2://192.168.17.15:10000/hivedb", "hiveuser", "hiveuser");
Statement stmt = con.createStatement();
ResultSet res = null;

String sql = "select count(*) from test_data";

System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
System.out.println("ok");
while (res.next()) {
System.out.println(res.getString(1));
}


mysql导入数据到Hive

bin/sqoop import --connect jdbc:mysql://10.95.3.49:3306/workflow --username shirdrn --P --table tags --columns 'id,tag' --create-hive-table -target-dir /hive/tag_db/tags -m 1 --hive-table tags --hive-import -- --default-character-set=utf-8

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值