zoukankan      html  css  js  c++  java
  • 4、使用 ImportTsv 将 Hive 数据导入 Hbase

    官网介绍

    • Hive 中的数据需要导入到 Hbase 表中,这里采用 Hbase 自带的 ImportTsv。
    • ImportTsv 导入数据时执行的是 MapReduce 任务,适合大数据导入。

    流程如下:

    一、将要导入 Hbase 的 Hive 表加载到临时表中,存储文件格式为 TXT,并以 作为分隔符

    临时表如下:

    CREATE TABLE `student`(
      `s_id` string,
      `s_name` string,
      `s_birth` string,
      `s_sex` string)
    ROW FORMAT SERDE
      'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
    WITH SERDEPROPERTIES (
      'field.delim'='	',
      'serialization.null.format'='')
    STORED AS INPUTFORMAT
      'org.apache.hadoop.mapred.TextInputFormat'
    OUTPUTFORMAT
      'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
    LOCATION
      'hdfs://hbc-cluster/user/hive/warehouse/tmp.db/student'
    

    二、使用 ImportTsv 生成 Hfile 文件

    • 这个步骤 ImportTsv 会去读取 hive_table_dir 中的文件,并分析 hbase table 的 region 分布,生成对应 region 的 hfile, 放到 hfile_path 中

    语法如下:

    $ bin/hbase org.apache.hadoop.hbase.mapreduce.ImportTsv -Dimporttsv.columns=a,b,c -Dimporttsv.bulk.output=hdfs://storefile-outputdir <tablename> <hdfs-data-inputdir>
    

    必须要指定 HBASE_ROW_KEY,且为第一个字段。

    hbase org.apache.hadoop.hbase.mapreduce.ImportTsv 
        -Dmapreduce.job.queuename=queue 
        -Dimporttsv.bulk.output=hdfs://hbc-cluster/tmp/hbase 
        -Dimporttsv.columns="HBASE_ROW_KEY,cf:s_name,cf:s_birth,cf:s_sex" 
        stream_data_warehouse:student 
        hdfs://hbc-cluster/user/hive/warehouse/tmp.db/student
    

    三、将上一步的 hfile 导入 Hbase table

    • 这里采用 CompleteBulkLoad

    语法如下:

    $ bin/hbase org.apache.hadoop.hbase.tool.LoadIncrementalHFiles <hdfs://storefileoutput> <tablename>
    
    hbase org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles 
        hdfs://hbc-cluster/tmp/hbase/ 
        stream_data_warehouse:student	
    
  • 相关阅读:
    java8中常用的新功能
    代码走查案例2
    redis的key设置每天凌晨过期的思路
    代码走查案例1
    一场没有序列化引发的血案
    面试总结
    hr相关的
    mysql底层原理
    如何学好并发编程
    流程图总结
  • 原文地址:https://www.cnblogs.com/xiexiandong/p/13139846.html
Copyright © 2011-2022 走看看