Creating an Index -- 创建一个索引
-
CREATE TABLE employees (
-
name STRING,
-
salary FLOAT,
-
subordinates ARRAY,
-
deductions MAPFLOAT>,
-
address STRUCTINT>
-
)
-
PARTITIONED BY (country STRING, state STRING);
CREATE TABLE employees (
name STRING,
salary FLOAT,
subordinates ARRAY,
deductions MAP,
address STRUCT
)
PARTITIONED BY (country STRING, state STRING);
Let’s index on the country partition only:
-
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.';
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:
-
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.';
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
-
ALTER INDEX employees_index
-
ON TABLE employees
-
PARTITION (country = 'US')
-
REBUILD;
ALTER INDEX employees_index
ON TABLE employees
PARTITION (country = 'US')
REBUILD;
Showing an Index
-
SHOW FORMATTED INDEX ON employees;
SHOW FORMATTED INDEX ON employees;
Dropping an Index
-
DROP INDEX IF EXISTS employees_index ON TABLE employees;
DROP INDEX IF EXISTS employees_index ON TABLE employees;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26613085/viewspace-1131361/
,如需转载,请注明出处,否则将追究法律责任。