第91课:Hive中Index和Bucket案例实战及存储类型实战详解

存储类型(rcfile textfile parquet)

在hive中索引 一般基于key 建立另一套存储机制,索引的存储可以与原有的存储格式不一样。建立索引一般都有分区,用空间换时间


ratings(userid)注意此处指定列名:

hive> create index index_ratings on table ratings(userid) as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler' with deferred rebuild;

//查看索引信息

hive> show index on ratings;

//查看索引发现是空的

hive> dfs -ls /bigdata/hive/warehouse/hivestudy.db/hivestudy__ratings_index_ratings__;


一般都要进行下面的alter,注意rebuild小写 

ALTER INDEX index_ratings on ratings rebuild;


上面的方法不推荐,一般都在分区上建立索引


假如在创建索引是我们使用“ WITH DEFERRED REBUILD”语句,则索引创建是为空,可以通过“Alter index ... rebuild”在一个partition上或所有partition上构建索引。


CREATE INDEX index_ratings ON TABLE users(userid) AS 'org.apache.hadoop.hive.sql.index.compact.CompactIndexHandler' WITH DEFERRED REBUILD;

上面的方法创建的索引看不到所以的数据;

一般都要进行下面的alter,注意rebuild小写 

ALTER INDEX index_users on users rebuild;

第一列:userid(我们是给予userid建立的) 第二列:数据在什么地方 第三列:partition



创建存储格式为rcfile的表

hive> create table table_rc(userid INT,name String,salary Double,address String,gender String) row format delimited fields terminated by '\t' lines terminated by '\n' stored as rcfile;

//注意执行load data local 会报错

hive> load data local inpath '/bigdata/learn_data/testHiveDriver.txt' into table table_rc;

Loading data to table default.table_rc

Failed with exception Wrong file format. Please check the file's format.

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask


用insert插入

hive> insert into table_rc select * from employeeforhaving;


桶表

大表一般用 桶表,提高大表的查询效率

桶表一般设置:hive.enforce.bucketing=true;  会有很多目录,可以认为每个目录就是一个桶,进行分门别类。

两张全表join操作用桶表


数据存储格式:

rcfile  能直接读进来一个数据进行rcfile吗???

不能必须先加载到表里然后导入;


来源于DT大数据梦工厂,如有笔误请提出。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值