首页 > 其他 > 详细

hive中的索引创建

时间:2019-12-18 12:47:19      阅读:151      评论:0      收藏:0      [点我收藏+]

1、在hive中创建索引所在表

create table if not exists h_odse.hxy(
id int,
name string,
hobby array<string>,
add map<string,string>
)
partitioned by (age int,sex string)
row format delimited
fields terminated by ‘,‘
collection items terminated by ‘-‘
map keys terminated by ‘:‘
lines terminated by ‘\n‘

2、在服务器内创建数据文件并导入数据

load data local inpath ‘/home/hetl/data‘ into table h_odse.hxy partition (age=10,sex=‘f‘);

3、从其他表中导入数据

load data local inpath ‘/home/hetl/data‘ into table h_odse.hxy partition(age=10,sex=‘boy‘) ;

from h_odse.hxy1
insert into h_odse.hxy partition(age,sex)
select id,name,hobby,add,age,sex distribute by age,sex;

4、创建指定索引表的索引

create index hxy_ind on table h_odse.hxy(id) as ‘org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler‘ with deferred rebuild in table h_odse.h_ind_table;

-----当in table h_odse.h_ind_table不加时  系统会自动创建一个索引表

5,使索引生效的话,必须执行

alter index hxy_ind on  h_odse.hxy rebuild; 

6,测试索引效果

select * from h_odse.hxy where id=1

未加索引时:

Time taken: 0.676 seconds, Fetched: 24 row(s)

添加索引后:

Time taken: 0.494 seconds, Fetched: 24 row(s)

7、删除索引

drop index hxy_ind on h_odse.hxy;

hive中的索引创建

原文:https://www.cnblogs.com/hhaahh/p/12059242.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!