hive的视图与索引的相关语法知识
来源:互联网 发布:怎么做淘宝内部券群主 编辑:程序博客网 时间:2024/04/29 02:59
1.views odds and ends
( the conceptual view still applies when the view and a query that uses it both contain an ORDER BY clause or a LIMIT clause. The view’s clauses are evaluated before the using query’s clauses.
For example, if the view has a LIMIT 100clause and the query has a LIMIT 200clause, you’ll get at most 100 results.)
CREATE VIEW IF NOT EXISTS shipments(time, part)
COMMENT 'Time and parts for shipments.'
TBLPROPERTIES ('creator' = 'me')
AS SELECT ...;
(创建视图跟创建表一样,为了防止视图引用的表发生变化以至于视图出错,所以带上IF NOT EXISTS)
(You can also add a COMMENT for any or all of the new column names. The comments are not “inherited” from the definition of the original table.
Also, if the AS SELECT contains an expression without an alias—e.g., size(cols)(the number of items in cols)—then Hive will use _CN as the name, where N is a number starting with 0. The view definition will fail if the AS SELECT clause is invalid.
Before the AS SELECT clause, you can also define TBLPROPERTIES, just like for tables.)
(Can also be used to copy a view, that is with a view as part of the LIKE expression:)
CREATE TABLE shipments2
LIKE shipments;
(You can also use the optional EXTERNAL keyword and LOCATION …clause, as before.)
--(A view is dropped in the same way as a table: As usual, IF EXISTS is optional.)
DROP VIEW IF EXISTS shipments;
(A view will be shown using SHOW TABLES(there is no SHOW VIEWS), however DROP TABLE cannot be used to delete a view.)
(As for tables, DESCRIBE shipments and DESCRIBE EXTENDED shipments displays the usual data for the shipment view. With the latter, there will be a tableType value in the Detailed Table Information indicating the “table” is a VIRTUAL_VIEW.)
(Finally, views are read-only. You can only alter the metadata TBLPROPERTIESfor a view:
ALTER VIEW shipments SET TBLPROPERTIES ('created_at' = 'some_timestamp');)
2.1创建索引:
需要被索引的表:
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);
创建的索引:
CREATE INDEX employees_index
ON TABLE employees (country)
AS 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler' [or 'BITMAP']
WITH DEFERRED REBUILD
IDXPROPERTIES ('creator = 'me', 'created_at' = 'some_time')
IN TABLE employees_index_table
PARTITIONED BY (country, name)
ALTER INDEX employees_index
ON TABLE employees
PARTITION (country = 'US')
REBUILD;
显示索引:
SHOW FORMATTED INDEX ON employees;
删除索引:
DROP INDEX IF EXISTS employees_index ON TABLE employees;
( the conceptual view still applies when the view and a query that uses it both contain an ORDER BY clause or a LIMIT clause. The view’s clauses are evaluated before the using query’s clauses.
For example, if the view has a LIMIT 100clause and the query has a LIMIT 200clause, you’ll get at most 100 results.)
CREATE VIEW IF NOT EXISTS shipments(time, part)
COMMENT 'Time and parts for shipments.'
TBLPROPERTIES ('creator' = 'me')
AS SELECT ...;
(创建视图跟创建表一样,为了防止视图引用的表发生变化以至于视图出错,所以带上IF NOT EXISTS)
(You can also add a COMMENT for any or all of the new column names. The comments are not “inherited” from the definition of the original table.
Also, if the AS SELECT contains an expression without an alias—e.g., size(cols)(the number of items in cols)—then Hive will use _CN as the name, where N is a number starting with 0. The view definition will fail if the AS SELECT clause is invalid.
Before the AS SELECT clause, you can also define TBLPROPERTIES, just like for tables.)
(Can also be used to copy a view, that is with a view as part of the LIKE expression:)
CREATE TABLE shipments2
LIKE shipments;
(You can also use the optional EXTERNAL keyword and LOCATION …clause, as before.)
--(A view is dropped in the same way as a table: As usual, IF EXISTS is optional.)
DROP VIEW IF EXISTS shipments;
(A view will be shown using SHOW TABLES(there is no SHOW VIEWS), however DROP TABLE cannot be used to delete a view.)
(As for tables, DESCRIBE shipments and DESCRIBE EXTENDED shipments displays the usual data for the shipment view. With the latter, there will be a tableType value in the Detailed Table Information indicating the “table” is a VIRTUAL_VIEW.)
(Finally, views are read-only. You can only alter the metadata TBLPROPERTIESfor a view:
ALTER VIEW shipments SET TBLPROPERTIES ('created_at' = 'some_timestamp');)
注意:You cannot use a view as a target of an INSERT or LOAD command.
2.1创建索引:
需要被索引的表:
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);
创建的索引:
CREATE INDEX employees_index
ON TABLE employees (country)
AS 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler' [or '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.';
ALTER INDEX employees_index
ON TABLE employees
PARTITION (country = 'US')
REBUILD;
显示索引:
SHOW FORMATTED INDEX ON employees;
删除索引:
DROP INDEX IF EXISTS employees_index ON TABLE employees;
0 0
- hive的视图与索引的相关语法知识
- hive的数据定义相关语法知识
- hive的数据操作的相关语法知识
- hive的数据查询的相关语法知识
- 视图的相关知识
- Hive的语法知识详解
- Hive的语法知识详解
- hive视图和索引的简单介绍
- [转]索引的相关语法
- oracle中与索引相关的视图---all_indexes
- hive相关语法与操作
- MySQL的视图与索引
- Oracle物化视图的相关知识
- sphinx 全文索引的相关知识
- 关于索引节点inode的相关知识
- 索引与视图的创建与应用
- 索引与视图的创建与应用
- 索引与视图的创建与应用
- ActionBar 样式详解 -- 样式 主题 简介
- nohup后台gbk编码错误 2016.04.29回顾
- tomcat配置
- android listview滑动设置浮标半透明效果
- 使用枚举类
- hive的视图与索引的相关语法知识
- 小议:如何保存SharePoint farm中的.WSP Solution?
- 使用反射来实现参数绑定
- PHP7+Apache2.4+Mysql安装配置(win7环境下)
- 理解Android编译命令
- Maven编译多子项目依赖
- 【Android UI】动态改变ListView布局
- as--actionBark
- JavaScript 进阶学习 7 DOM对象,控制HTML元素