zoukankan      html  css  js  c++  java
  • 利用hive-hbase表做hive表快速入库hbase功能,纬度表的查询

    有个需求是纬度表需要秒出数据,首先表刚好也是1-1批对的情况,首先想到了利用hbase的索引机制。(表数据大概在4--30E之间)

    虽然网上有很多直接建立hive表,自动创建hbase表的例子,但是这种情况不能进行hbase表的region预分区,导致热点问题比较严重。所以hive和hbase表要分开建立再关联起来。

    1.建立hbase表

    create 'xxxxx', {NAME => 'info',COMPRESSION => 'SNAPPY'},SPLITS => ['xxx|','xxx|','xxx|','xxx|','xxx|','xx|'']。预分区方式要自己看hbase的rowkey和实际数据入库情况而定,比如hbase的masterui的request是否请求均匀,如果大量数据偏移必须进行region预分区的切分细点。

    2.进行hive的表建立

    hive关联hbase表
    CREATE EXTERNAL TABLE xxxxx.xxxxx(row string,ipaddress string,country string,province string,city string,isp string)
    stored BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
    WITH serdeproperties ("hbase.columns.mapping" = ":key,info:ipaddress,info:country,info:province,info:city,info:isp")
    tblproperties ('hbase.table.name' = 'xxxxx');

      1.此表必须为外部表不然会报错

      2.必须指定rowkey

    3.查询自己要的表做全量数据入库

    insert into table xxx.xxxx
    select ip as key,concat_ws(xxxx) as ipaddress,country,province,city,isp from xxxx.xxxx where country='xx';

    4.写脚本把每天增量纬度数据相应insert入库就好了

    注意:1.这种表比直接建立hive自动建立hbase表有个好处就是删除hive表,hbase不会受到影响。删除hbase表hive也不会受到影响(我记得是如此,可以后续再试试),而hive直接自动建立hbase的表删除hive会带着hbase表一起消失了。

    2.表数据实际上应该是存在hbase中,所以索引查询非常的块,实际测试5E数据索引1万内容大概1秒左右

  • 相关阅读:
    webDriver API——第11部分Remote WebDriver
    webDriver API——第10部分Chrome WebDriver
    转:Java NIO系列教程(六) File Channel
    转:Java NIO系列教程(五) 通道之间的数据传输
    转:Java NIO系列教程(四) Scatter/Gather
    转:Java NIO系列教程(三) Buffer
    转:Java NIO系列教程(二) Channel
    Java-优秀博客推荐
    java.net.Socket/java.net.ServerSocket-TCP Socket编程
    转:Java NIO系列教程(一)Java NIO 概述
  • 原文地址:https://www.cnblogs.com/yaohaitao/p/12573865.html
Copyright © 2011-2022 走看看