Hive擴展功能(八)--表的索引

軟件環境:

linux系統: CentOS6.7
Hadoop版本: 2.6.5
zookeeper版本: 3.4.8


主機配置:

一共m1, m2, m3這三部機, 每部主機的用戶名都爲centos
192.168.179.201: m1 
192.168.179.202: m2 
192.168.179.203: m3 

m1: Zookeeper, Namenode, DataNode, ResourceManager, NodeManager, Master, Worker
m2: Zookeeper, Namenode, DataNode, ResourceManager, NodeManager, Worker
m3: Zookeeper, DataNode, NodeManager, Worker

資料

官方資料:
    https://cwiki.apache.org/confluence/display/Hive/IndexDev
    https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-Create/Drop/AlterIndex




一. 編輯hive-site.xml文件

<property>
    <name>hive.optimize.index.filter</name>
    <value>true</value>
</property>
<property>
    <name>hive.optimize.index.groupby</name>
    <value>true</value>
</property>
<property>
    <name>hive.index.compact.file.ignore.hdfs</name>
    <value>true</value>
</property>








二. 建立Hive表索引

官方資料:
    https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Indexing

1.建立/構造, 顯示, 刪除索引:

create index table01_index on table table01 (column2) as 'compact';
show index on table01;
drop index table01_index on table01;

2.建立時重構, 格式化顯示 (with column names), 刪除索引:

create index table02_index on table table02 (column3) as 'compact' with deferred rebuild;
alter index table02_index on table2 rebuild;
show formatted index on table02;
drop index table02_index on table02;

3.建立索引視圖, 構建, 顯示, 刪除:

create index table03_index on table table03 (column4) as 'bitmap' with deferred rebuild;
alter index table03_index on table03 rebuild;
show formatted index on table03;
drop index table03_index on table03;

4.在新表中建立索引:

create index table04_index on table table04 (column5) as 'compact' with deferred rebuild in table table04_index_table;

5.建立索引以RCFile的存儲格式:

create index table05_index on table table05 (column6) as 'compact' stored as RCFile;

6.建立索引以TextFile的存儲格式:

create index table06_index on table table06 (column7) as 'compact' row format delimited fields terminated by '\t' stored as textFile;

7.建立索引和索引的屬性:

create index table07_index on table table07 (column8) as 'COMPACT' idxproperties ("prop1"="value1", "prop2"="value2");

8.建立索引和表的屬性:

create index table08_index on table table08 (column9) as 'compact' tblproperties ("prop3"="value3", "prop4"="value4");

9.索引若是存在則刪除:

drop index if exists table09_index on table09;

10.重構一個分區的數據:

alter index table10_index on table10 partition (columnX='valueQ', columnY='valueR') rebuild;
相關文章
相關標籤/搜索