HIVE HBASE 整合
HBase 整合 hive
2023-09-11 14:14:44 时间
一直想将hbase 与hive整合在一起,因为公司项目工期一期紧似一期,故一直推后。还不知道推到什么时候呢。
今天尝试编译hive,看着官方文档。感觉非常easy:
1、svn co http://svn.apache.org/repos/asf/hive/trunk hive 先下载源码吧。我下载最新代码0.14
2、cd hive ; mvn package -Phadoop-2,dist, 编译后须要一大堆測试信息,故去掉測试过程
mvn package -Phadoop-2,dist -Dtar -DskipTests,
刚開始编译到common的时候报错。 进入common模块单独编译,要增加hadoop2,而且要有hadoop2的相关文件。
下载一大堆文件后,显示编译成功。
注意编译hadoop本地包的时候须要增加-Pnative
3、在hbase中创建表:
public static void createTable(HBaseAdmin admin) { try { TableName tn = TableName.valueOf(TABLENAME); HTableDescriptor tableDescripter = new HTableDescriptor(tn); HColumnDescriptor column = new HColumnDescriptor("x"); // column.setTimeToLive(600000); // column.setCompressionType(Compression.Algorithm.LZO); tableDescripter.addFamily(column); byte[][] regions = new byte[][]{ Bytes.toBytes("1"), Bytes.toBytes("2"), Bytes.toBytes("3"), Bytes.toBytes("4"), Bytes.toBytes("5"), Bytes.toBytes("6"), Bytes.toBytes("7"), Bytes.toBytes("8"), Bytes.toBytes("9"), Bytes.toBytes("0") }; admin.createTable(tableDescripter,regions); } catch (IOException ex) { Logger.getLogger(HbaseConfig.class.getName()).log(Level.SEVERE, null, ex); } }
4、在hbase 中插入数据:
HbaseUtil util = new HbaseUtil(); try (HTable table = new HTable(HbaseConfig.getConfig(), HbaseConfig.TABLENAME)) { for (int i = 0; i < 10; i++) { String dmpid = generateDmpid(); String channel = "5030"; String value = "dmpid" + dmpid; Put p = new Put(Bytes.toBytes(reverse(dmpid))); p.add(Bytes.toBytes("x"), Bytes.toBytes(channel), Bytes.toBytes(value)); if (value != null && !"".equals(value) && !"null".equals(value)) { p.add(Bytes.toBytes("x"), Bytes.toBytes("5020"), Bytes.toBytes(value)); //channel uid } table.put(p); table.flushCommits(); } }5、在hive中创建关联表
使用下面命令启动hive:
hive --hiveconf hbase.zookeeper.quorum=host107,host108,host109
启动完毕在hive控制台运行以下命令
CREATE EXTERNAL TABLE emaruser(key string, google string,tanx string,tencent string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,x:5010,x:5020,x:5030") TBLPROPERTIES("hbase.table.name" = "emar_user_relation");
6、在hive中查询成功
hive> select * from emaruser; OK 0054308844100908791141 NULL dmpid1411978090014488034500 NULL 0101677395300318791141 NULL dmpid1411978130035937761010 dmpid1411978130035937761010 0529909431699808791141 NULL dmpid1411978089961349099250 NULL 0816959407102198791141 NULL dmpid1411978912017049596180 dmpid1411978912017049596180 2144264024543118791141 dmpid1411978113454204624412 dmpid1411978113454204624412 NULL 2309952861202198791141 NULL dmpid1411978912021682599032 dmpid1411978912021682599032 3106277691400318791141 NULL dmpid1411978130041967726013 dmpid1411978130041967726013 3109618614400318791141 NULL dmpid1411978130044168169013 dmpid1411978130044168169013 3207091484943118791141 dmpid1411978113494841907023 dmpid1411978113494841907023 NULL 3265583421200318791141 NULL dmpid1411978130021243855623 dmpid1411978130021243855623 3449017552200908791141 NULL dmpid1411978090022557109443 NULL 3645762585202198791141 NULL dmpid1411978912025852675463 dmpid1411978912025852675463 3660257098743118791141 dmpid1411978113478907520663 dmpid1411978113478907520663 NULL 3701620688943118791141 dmpid1411978113498860261073 dmpid1411978113498860261073 NULL 380639403302198791141 NULL dmpid141197891203304936083 dmpid141197891203304936083
大功告成。
by the way
使用两个节点的client,hbase入库达到35000条/秒。
集群6台server。
相关文章
- Hbase学习之javaApI封装
- hbase 单机+伪分布环境搭建学习-1
- Hbase参数调优
- 高可用Hadoop平台-HBase集群搭建
- hbase 学习(十三)集群间备份原理
- Hbase 预写日志WAL处理源码分析之 LogCleaner
- 启动HBase抛出org.apache.hadoop.hbase.ClockOutOfSyncException异常:hmaster正常,节点hregionserver启动失败
- HBase get查询命令及VERSIONS版本
- hbase 基本的JavaApi 数据操作及数据过滤(filter)
- E-MapReduce集群如何使用Phoenix on HBase
- 技术实操丨HBase 2.X版本的元数据修复及一种数据迁移方式
- Hbase启动hbase shell运行命令报Class path contains multiple SLF4J bindings.错误
- 揭秘FaceBook Puma演变及发展——FaceBook公司的实时数据分析平台是建立在Hadoop 和Hive的基础之上,这个根能立稳吗?hive又是sql的Map reduce任务拆分,底层还是依赖hbase和hdfs存储
- HBase和ZooKeeper
- hadoop+hbase适合存储海量小图片吗?
- HBASE中常见问题
- Hbase调优
- hbase回收站清理周期设置为1天