hive的靜態分區和動態分區

  1. 分區表:
    分區是表的部分列的集合
    一般爲頻繁使用的數據建立分區,在查找分區中數據時不用掃描全表,有利於提高查找效率
    Hive每個表有一個相應的目錄存儲數據,表中的的每一個分區對應表目錄下的一個子目錄,每個分區中的數據存儲在對應子目錄下的文件中
    關鍵字是partitioned
    分區表實際上是將表文件分成多個有標記的小文件方便查詢
    partitned by子句中定義的列是表中正式的列(分區列),但是數據文件內並不包含這些列(僞分列)
    刪除分區:alter table 表名 drop partition(dt=’20160301’);
    增加分區:alter table 表名 add partition(dt=’20160301’);

  2. 靜態分區 : 指定列的值 ;由用戶指定的數據所在的分區
    建表
    Create table student1(id int,name string)
    Partitioned by(aca string,class string)
    Row format delimited fields terminated by ‘,’;
    導入數據
    Load data local inpath ‘/bigdata/10.txt into table student1
    partition(aca=’computer’,class=’034’);

  3. 動態分區 : 不指定列的值 可以設置部分列爲動態分區列
    不允許主分區爲動態分區列,而副分區爲靜態分區列
    建表
    Create table student(id int,name string)
    Partitioned by(aca string,class string)
    Row format delimited fields terminated by ‘,’;
    設置模式爲動態
    Set hive.exec.dynamic.partition.mode=nonstrict;
    Set hive.exec.dynamic.partition=true;
    導入數據
    Insert overwrite table student partition(aca,class)
    Select id,name,aca,class from student1
    Where class=’034’;

發佈了54 篇原創文章 · 獲贊 2 · 訪問量 2319
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章