hive索引

创建索引

hive> create index [index_studentid] on table st(studentid)

 as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler'

 with deferred rebuild

 IN TABLE index_table_st;

OK Time taken: 12.219 seconds

 

org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler :创建索引需要的实现类

index_studentid:索引名称

st:表名

index_table_st:创建索引后的表名

查看索引表(index_table_st)没有数据

hive> select*from index_table_st;
OK
Time taken: 0.295 seconds
  

加载索引数据

hive> alter index index_studentid on st rebuild;

MapReduce Jobs Launched: Stage-Stage-1: Map: 1 Reduce: 1 Cumulative CPU: 4.68 sec HDFS Read: 10282 HDFS Write: 537 SUCCESS Total MapReduce CPU Time Spent: 4 seconds 680 msec OK Time taken: 280.693 seconds

查询索引表中数据

hive> select*from index_table_st;

OK

1 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt [0]

2 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt [28]

3 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt [56]

4 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt [85]

5 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt [113]

6 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt [143]

Time taken: 2.055 seconds, Fetched: 6 row(s)

查看hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt

[root@node4 node4]# hdfs dfs -text /opt/hive/warehouse/st/sutdent.txt; 001 0

BeiJing xinlang@.com 002 1

ShangHaixinlang@.com 003 0

ShegZhen xinlang@.com 004 1

NanJing xinlang@.com 005 0

GuangDong xinlang@.com 006 1

HaiNan xinlang@.com

 

删除索引

DROP INDEX index_studentid on st;

查看索引hive> SHOW INDEX on st;
OK
index_studentid         st               studentid               index_table_st    compact                 
Time taken: 0.487 seconds, Fetched: 1 row(s)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值