1. 程式人生 > 其它 >Hive(五)索引、檢視、定時器

Hive(五)索引、檢視、定時器

最近看了一遍hive的文件,本文是為了記錄文件中將來會可用東西,並非最全的《文件》,望諒解

一:索引

索引

           適用於大多數索引情況:

                      create index table01_index on table table01 (column2) as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler' with deferred rebuild; 

           適用於排序後值比較小情況:

                      create index table01_index on table table01 (column2) as 'bitmap' with deferred rebuild; 

           重新整理索引:alter index table02_index on table2 rebuild;

           顯示索引:show formatted index on table02;

           刪除索引:drop index table02_index on table02;

           分割槽索引:alter index table10_index on table10 partition (columnx='valueq', columny='valuer') rebuild;;

二:檢視

檢視

           建立檢視:create view onion_referrers comment 'referrers to the onion website' as select distinct referrer_url from page_view where page_url='http://www.theonion.com';

           刪除檢視:drop view if exists onion_referrers; 

           修改檢視:alter table view as select *from;   alter table view set tblproperties ('external' = 'true');  

           顯示檢視:show views in test1 "test_*";        

物化檢視(相當於實體表)

           建立物化檢視:create materialized view onion_referrers comment 'referrers to the onion website' as select distinct referrer_url from page_view where page_url='http://www.theonion.com';

           刪除物化檢視:drop materialized view onion_referrers;

           重新整理物化檢視:alter materialized view onion_referrers enable|disable rewrite;

           顯示物化檢視:show materialized views [in/from database_name] [like 'pattern_with_wildcards’];

 

三:定時器

定時器

建立定時器:create scheduled query sc1 cron '0 */10 * * * ? *' as insert into t values (1);

                     create scheduled query mv_rebuild cron '0 */10 * * * ? *' defined as alter materialized view mv1 rebuild;

                     create scheduled query ingest every 10 minutes defined as alter materialized view mv1 rebuild;

取消定時器:alter scheduled query t_analyze disable;

查詢定時器:select * from information_schema.scheduled_queries s where schedule_name='sc1';

查詢定時器結果:select * from information_schema.scheduled_executions s where schedule_name='sc1' order by scheduled_execution_id desc limit 1;