通过Hive查询 HBase
发表于:2024-09-30 作者:千家信息网编辑
千家信息网最后更新 2024年09月30日,线上的zipkin的存储是利用的HBase0.94.6,一开始Dev想直接写MR来做离线分析,后来聊了下发现走Hive会提高开发的效率(当然,这里查询HBase的SQL接口还有phoenix,Impa
千家信息网最后更新 2024年09月30日通过Hive查询 HBase
线上的zipkin的存储是利用的HBase0.94.6,一开始Dev想直接写MR来做离线分析,后来聊了下发现走Hive会提高开发的效率(当然,这里查询HBase的SQL接口还有phoenix,Impala等,只不过都还不够成熟,并且是离线分析不是adhocquery,BTW,前阶段和intel的聊过他们的Hive Over HBase是跳过MR的,效率非常赞,不过钱也略贵了=.=);
其实用Hive查询HBase非常简单:
//首先在HBase里建一张表并插入几条数据hbase(main):003:0> create 'table_inhbase','cf'0 row(s) in 1.2060 seconds=> Hbase::Table - table_inhbasehbase(main):004:0> listTABLE table_inhbase 1 row(s) in 0.0350 secondshbase(main):005:0> put 'table_inhbase','row1','cf:a','value1'0 row(s) in 0.0830 secondshbase(main):006:0> put 'table_inhbase','row2','cf:a','value2'0 row(s) in 0.0200 secondshbase(main):007:0> put 'table_inhbase','row3','cf:b','value3'0 row(s) in 0.0180 secondshbase(main):008:0> scan 'table_inhbase'ROW COLUMN+CELL row1 column=cf:a, timestamp=1383736436773,value=value1 row2 column=cf:a, timestamp=1383736462917,value=value2 row3 column=cf:b, timestamp=1383736476017,value=value3 3 row(s) in 0.0660 seconds//在Hive里创建一个外部表,注意要在hive-site.xml加入ZK,否则会hang住,一直去重试localhost:2181CREATE EXTERNAL TABLE ext_table_inhbase(key string, avalue string,bvaluestring) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" ="cf:a,cf:b") TBLPROPERTIES("hbase.table.name" = "table_inhbase");hive> CREATE EXTERNAL TABLE ext_table_inhbase(key string, avaluestring,bvalue string) > STORED BY'org.apache.hadoop.hive.hbase.HBaseStorageHandler' > WITH SERDEPROPERTIES("hbase.columns.mapping" = "cf:a,cf:b") > TBLPROPERTIES("hbase.table.name" ="table_inhbase");OK//注意,这里要加入这2个jar包:hbase-0.94.6-cdh5.4.0.jar,hive-hbase-handler-0.10.0-cdh5.4.0.jar否则会抛出异常hive> select * from ext_table_inhbase;OKrow1 value1 NULLrow2 value2 NULLrow3 NULL value3Time taken: 0.609 secondshive> select key,avalue from ext_table_inhbase;java.io.IOException: Cannot create an instance of InputSplit.apache.hadoop.hive.hbase.HBaseSplit:Classorg.apache.hadoop.hive.hbase.HBaseSplit not found at org.apache.hadoop.hive.ql.io.HiveInputFormat$HiveInputSplit.readFields(HiveInputFormat.java:146) atorg.apache.hadoop.io.serializer.WritableSerialization$WritableDeserializer.deserialize(WritableSerialization.java:73) atorg.apache.hadoop.io.serializer.WritableSerialization$WritableDeserializer.deserialize(WritableSerialization.java:44) atorg.apache.hadoop.mapred.MapTask.getSplitDetails(MapTask.java:356) atorg.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:388) at org.apache.hadoop.mapred.MapTask.run(MapTask.java:332) atorg.apache.hadoop.mapred.Child$4.run(Child.java:268) atjava.security.AccessController.doPrivileged(Native Method) atjavax.security.auth.Subject.doAs(Subject.java:396) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1408)hive> select key,avalue from ext_table_inhbase;Total MapReduce jobs = 1Launching Job 1 out of 1Number of reduce tasks is set to 0 since there's no reduce operatorHadoop job information for Stage-1: number of mappers: 1; number ofreducers: 019:33:55,386 Stage-1 map = 0%, reduce = 0:34:01,472 Stage-1 map = 100%, reduce = 0%, CumulativeCPU 2.73 sec19:34:02,495 Stage-1 map = 100%, reduce = 0%, CumulativeCPU 2.73 sec19:34:03,512 Stage-1 map = 100%, reduce = 100%,Cumulative CPU 2.73 secMapReduce Total cumulative CPU time: 2 seconds 730 msecEnded Job = job_201311061424_0003MapReduce Jobs Launched:Job 0: Map: 1 Cumulative CPU: 2.73 sec HDFS Read:255 HDFS Write: 39 SUCCESSTotal MapReduce CPU Time Spent: 2 seconds 730 msecOKrow1 value1row2 value2//尝试通过HiveServer去查询beeline> !connect jdbc:hive2://test-2:10000 hdfs hdfsorg.apache.hive.jdbc.HiveDriver Connecting to jdbc:hive2://test-2:10000Connected to: Hive (version 0.10.0)Driver: Hive (version 0.10.0-cdh5.4.0)Transaction isolation: TRANSACTION_REPEATABLE_READ0: jdbc:hive2://test-2:10000> show databases;+----------------+| database_name |+----------------+| default |+----------------+1 row selected (1.483 seconds)0: jdbc:hive2://test-2:10000> show tables;+--------------------+| tab_name |+--------------------+| ext_table_inhbase ||test |+--------------------+2 rows selected (0.657 seconds)0: jdbc:hive2://test-2:10000> select count(*) from ext_table_inhbase;+------+| _c0 |+------+| 3 |+------+
查询
效率
分析
成熟
不够
只不过
接口
数据
阶段
建一
存储
尝试
开发
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
中小学教育软件开发
安卓软件开发后职业规划
access多数据库合并
软件开发用什么去测试代码
sql数据库一张表怎么改
上海erp软件开发服务费
基于gis的属性数据库
如何查看服务器磁盘状态
松田职业学院网络技术
泰安互云码软件开发公司
二道区智能网络技术什么价格
网络安全普法教育宣传片范文
网络安全等级保护共分为几级
国网信通公司网络安全分析室
英雄联盟服务器是独立的么
服务器安全与加固
软件检测与软件开发
阿里服务器里文件如何管理
湖南仓储生鲜配送软件开发
数据库加密存储 如何搜索
地瓜网络技术视频
计算机网络技术有哪些东西
巨人网络技术分析
网络技术近3年参考文献
利用校园网数据库的感悟
泰安互云码软件开发公司
软件开发评审需要什么
好看的网络安全绘画
网络数据库编程软件有哪些
服务器支架滑轨