HiveQL:索引

来源:互联网 发布:linux 脚本 while 编辑:程序博客网 时间:2024/04/27 08:28
Hive只有有限的索引功能,Hive中没有普通关系型数据库中键的概念。但是还是可以对一些字段建立索引来加速某些操作的。一张表的索引数据存储在另一张表中。

同时因为这是一个相对比较新的功能,所以目前还没有提供很多的选择。然而,索引处理模块被设计成为可以定制的Java编码的插件。因此,用户可以根据实际需要对其进行是吸纳,以满足自身的需求。

创建索引
create index emp_index on table emp(country)
As 'org.apache.hadoop.hive.hq.index.compact.CompactIndexHandler'
with deferred rebuild
idxproperties('creator'='me' ,'created_at'='some_timestamp')
in table emp_index_tab
partitioned by (country,name)
comment 'emp indexed by country and name';

重建索引
alter index emp_index on table emp partition (country='US') rebuild ;

显示索引
show format index on emp ;

删除索引
drop index if exists emp_index on table emp ;

实现一个定制化的索引处理器
Hive Wiki页面具有实现一个定制化的索引处理器的完整例子;当然用户也可使用CompactIndexHandler中源代码作为例子学习。
0 0
原创粉丝点击