• hive到hbase的使用


    一、简单介绍

    hive的元数据保存在metastore里面,真实的数据一般位于hdfs中,可以通过hql来对数据进行分析。hbase中的数据也是存放在hdfs上的,可不可以使用hive来分析hbase中的数据呢?

    二、hive表到hbase表的映射

    2.1hbase表t1的结构和其中的数据如下图

    2.2创建hive表映射到hbase的表

    首先输入下面的命令进入hive的客户端

    hive --auxpath /usr/local/hive-0.14.0/lib/hive-hbase-handler-0.14.0.jar,/usr/local/hive-0.14.0/lib/zookeeper-3.4.5.jar -hiveconf hbase.master=hadoop26:60000 -hiveconf hbase.zookeeper.quorum=hadoop26

    使用下面的语句创建hive表,数据是存储在hbase中的

    CREATE EXTERNAL TABLE h1
    (id string, name string,age int,gender string)
    STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
    WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,f1:name,f1:age,f1:gender") TBLPROPERTIES("hbase.table.name" = "t1");

    三、使用hql来查询hbase中的数据

    向hbase表t1中插入数据

    put 't1','4','f1:name','zhaoliu'

     再次从hive中查询

     

    hbase中的数据和hive是同步的,这也说明hive表的数据是位于hbase中的

    四、使用hive向hbase中插入数据

    4.1首先是需要创建一个hive临时表

    create table h1_tmp
    (id int,name string,age int,gender string)
    row format delimited
    fields terminated by ' ';

    4.2向临时表中批量的上传数据

    load data local inpath '/root/temp.txt' into table h1_tmp;

    4.3把临时表h1_tmp的数据插入到目标表

    insert into table h1 select * from h1_tmp; 

    五、注意

    如果hbase中添加新的列,那么hive中是查询不到的。

    因为hive创建表的字段没有hbase新列的映射。如下面的情况。

    put 't1','4','f1:birthday','1993'

    但是在hive中查不到

  • 相关阅读:
    ASP.NET服务器控件开发(4)复合控件
    C#特性对象集合初始化器
    C#特性匿名类型与隐式类型局部变量
    在Handler中使用Session
    使用 UDPClient 生成聊天客户端
    当下10大最热门的网站开发技术
    C#特性扩展方法
    50个非常有用的PHP工具
    c# 调用.bat文件
    c# 特性/属性(Attribute) 以及使用反射查看自定义特性
  • 原文地址:https://www.cnblogs.com/dongdone/p/5681295.html
Copyright © 2020-2023  润新知