本帖最后由 nettman 于 2014-7-18 21:31 编辑
问题导读
1、Hive可以创建哪些索引?
2、Hive如何创建分区索引、唯一性索引?
Creating an Index -- 创建一个索引
[sql]
CREATE TABLE employees (
name STRING,
salary FLOAT,
subordinates ARRAY<STRING>,
deductions MAP<STRING, FLOAT>,
address STRUCT<street:STRING, city:STRING, state:STRING, zip:INT>
)
PARTITIONED BY (country STRING, state STRING); 复制代码
Let’s index on the country partition only:(让我们唯一分区索引)
[sql]
CREATE INDEX employees_index
ON TABLE employees (country)
AS 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler'
WITH DEFERRED REBUILD
IDXPROPERTIES ('creator = 'me', 'created_at' = 'some_time')
IN TABLE employees_index_table
PARTITIONED BY (country, name)
COMMENT 'Employees indexed by country and name.'; 复制代码
Bitmap Indexes
Hive v0.8.0 adds a built-in bitmap index handler. Bitmap indexes are commonly used
for columns with few distinct values. Here is our previous example rewritten to use the
bitmap index handler:
(Hive 0.8.0添加了一个内置的位图索引处理程序。位图索引是常用的具有几个不同值的列。这是我们的前一个例子重写使用,位图索引处理程序:)
[sql]
CREATE INDEX employees_index
ON TABLE employees (country)
AS 'BITMAP'
WITH DEFERRED REBUILD
IDXPROPERTIES ('creator = 'me', 'created_at' = 'some_time')
IN TABLE employees_index_table
PARTITIONED BY (country, name)
COMMENT 'Employees indexed by country and name.'; 复制代码
Rebuilding the Index
(重建索引)
[sql]
ALTER INDEX employees_index
ON TABLE employees
PARTITION (country = 'US')
REBUILD; 复制代码
Showing an Index
(查看索引)
[sql]
SHOW FORMATTED INDEX ON employees; 复制代码
Dropping an Index
(删除索引)
[sql]
DROP INDEX IF EXISTS employees_index ON TABLE employees; 复制代码