zoukankan      html  css  js  c++  java
  • Hive分区表与分桶

    分区表

    在Hive Select查询中。通常会扫描整个表内容,会消耗非常多时间做不是必需的工作。


    分区表指的是在创建表时,指定partition的分区空间。

    分区语法

    create table tablename
    name string
    )
    partitioned by(key type,…)

    create table if not exists employees(
    name string,
    salary string,
    subordinates array<string>,
    deductions map<string,float>,
    address struct<street:string,city:string,state:string,zip:int>
    )
    partitioned by (dt string,type string)
    row format delimited fields terminated by '	' 
    collection items terminated by ','
    map keys terminated by ':'
    lines terminated by '
    ' 
    stored as textfile
    ;

    分区表操作
    添加分区

    Alter table employees add if not exists partition(country='xxx'[,state='yyyy'])
    Alter table employees add if not exists partition(dt='20140715',type='test');

    删除分区

    Alter table employees drop if exists partition(country='xxx'[,state='yyyy’)

    Hive分桶

    对于每个表(table)或者分区。Hive能够进一步组织成桶,也就是说捅是更为细粒度的数据范困划分。

    Hive是针对某一列进行分捅。

    Hive採用对列值哈希,然后除以捅的个数求余的方式决定该条记录存放在哪个桶其中。

    优点
    获得更高的查询处理效率。
    使取样(sampling)更高效

    分桶语法

    create table bucketed_user(
    id string ,
    name string
    )
    clustered by (id) sorted by (name) into 4 buckets
    row format delimited fields terminated by '	' 
    stored as textfile;

    设置

    set hive.enforce.bucketing = true;

    插入数据

    insert overwrite table bucketed_user select addr ,name from testtable;

    Hive分区与分桶比較

  • 相关阅读:
    Angularjs 设置全局变量的3种方法
    prevent to do sth 与 prevent sb (from) doing 用法
    软件测试技术对程序员的重要性
    Javascript中setTimeout()以及clearTimeout( )的使用
    Javascript异步编程的常用方法
    软件设计原则总结
    为sublime Text3 安装插件JS Format
    javascript中 if(变量)和if(变量==true)的区别
    Ping 命令
    ipconfig
  • 原文地址:https://www.cnblogs.com/mthoutai/p/7066609.html
Copyright © 2011-2022 走看看