Create/Drop/Alter View

Version information

Icon

View support is only available in Hive 0.6 and later.

Create View

CREATE VIEW [IF NOT EXISTS] view_name [(column_name [COMMENT column_comment], ...) ]
  [COMMENT view_comment]
  [TBLPROPERTIES (property_name = property_value, ...)]
  AS SELECT ...;

CREATE VIEW creates a view with the given name. An error is thrown if a table or view with the same name already exists. You can use IF NOT EXISTS to skip the error.

If no column names are supplied, the names of the view's columns will be derived automatically from the defining SELECT expression. (If the SELECT contains unaliased scalar expressions such as x+y, the resulting view column names will be generated in the form _C0, _C1, etc.) When renaming columns, column comments can also optionally be supplied. (Comments are not automatically inherited from underlying columns.)

A CREATE VIEW statement will fail if the view's defining SELECT expression is invalid.

Note that a view is a purely logical object with no associated storage. (No support for materialized views is currently available in Hive.) When a query references a view, the view's definition is evaluated in order to produce a set of rows for further processing by the query. (This is a conceptual description; in fact, as part of query optimization, Hive may combine the view's definition with the query's, e.g. pushing filters from the query down into the view.)

A view's schema is frozen at the time the view is created; subsequent changes to underlying tables (e.g. adding a column) will not be reflected in the view's schema. If an underlying table is dropped or changed in an incompatible fashion, subsequent attempts to query the invalid view will fail.

Views are read-only and may not be used as the target of LOAD/INSERT/ALTER. For changing metadata, see ALTER VIEW.

A view may contain ORDER BY and LIMIT clauses. If a referencing query also contains these clauses, the query-level clauses are evaluated after the view clauses (and after any other operations in the query). For example, if a view specifies LIMIT 5, and a referencing query is executed as (select * from v LIMIT 10), then at most 5 rows will be returned.

Starting with Hive 0.13.0, the view's select statement can include one or more common table expressions (CTEs) as shown in the SELECT syntax. For examples of CTEs in CREATE VIEW statements, see Common Table Expression.

Example of view creation:

CREATE VIEW onion_referrers(url COMMENT 'URL of Referring page')
  COMMENT 'Referrers to The Onion website'
  AS
  SELECT DISTINCT referrer_url
  FROM page_view
  WHERE page_url='http://www.theonion.com';

Use SHOW CREATE TABLE to display the CREATE VIEW statement that created a view.

Drop View

DROP VIEW [IF EXISTS] view_name;

DROP VIEW removes metadata for the specified view. (It is illegal to use DROP TABLE on a view.)

When dropping a view referenced by other views, no warning is given (the dependent views are left dangling as invalid and must be dropped or recreated by the user).

In Hive 0.7.0 or later, DROP returns an error if the view doesn't exist, unless IF EXISTS is specified or the configuration variable hive.exec.drop.ignorenonexistent is set to true.

Example:

DROP VIEW onion_referrers;

Alter View Properties

ALTER VIEW view_name SET TBLPROPERTIES table_properties;
 
table_properties:
  : (property_name = property_value, property_name = property_value, ...)

As with ALTER TABLE, you can use this statement to add your own metadata to a view.

Alter View As Select

Version information

Icon

As of Hive 0.11.

ALTER VIEW view_name AS select_statement;

Alter View As Select changes the definition of a view, which must exist. The syntax is similar to that for CREATE VIEW and the effect is the same as for CREATE OR REPLACE VIEW.

Note: The view must already exist, and if the view has partitions, it could not be replaced by Alter View As Select.

Create/Drop/Alter Index

Version information

Icon

As of Hive 0.7.

This section provides a brief introduction to Hive indexes, which are documented more fully here:

In Hive 0.12.0 and earlier releases, the index name is case-sensitive for CREATE INDEX and DROP INDEX statements. However, ALTER INDEX requires an index name that was created with lowercase letters (see HIVE-2752). This bug is fixed in Hive 0.13.0 by making index names case-insensitive for all HiveQL statements. For releases prior to 0.13.0, the best practice is to use lowercase letters for all index names.

Create Index

CREATE INDEX index_name
  ON TABLE base_table_name (col_name, ...)
  AS index_type
  [WITH DEFERRED REBUILD]
  [IDXPROPERTIES (property_name=property_value, ...)]
  [IN TABLE index_table_name]
  [
     [ ROW FORMAT ...] STORED AS ...
     | STORED BY ...
  ]
  [LOCATION hdfs_path]
  [TBLPROPERTIES (...)]
  [COMMENT "index comment"];

CREATE INDEX creates an index on a table using the given list of columns as keys. See CREATE INDEX in the Indexes design document.

Drop Index

DROP INDEX [IF EXISTS] index_name ON table_name;

DROP INDEX drops the index, as well as deleting the index table.

In Hive 0.7.0 or later, DROP returns an error if the index doesn't exist, unless IF EXISTS is specified or the configuration variable hive.exec.drop.ignorenonexistent is set to true.

Alter Index

ALTER INDEX index_name ON table_name [PARTITION partition_spec] REBUILD;

ALTER INDEX ... REBUILD builds an index that was created using the WITH DEFERRED REBUILD clause, or rebuilds a previously built index. If PARTITION is specified, only that partition is rebuilt.

Create/Drop Function

Temporary Functions

Create Temporary Function

CREATE TEMPORARY FUNCTION function_name AS class_name;

This statement lets you create a function that is implemented by the class_name. You can use this function in Hive queries as long as the session lasts. You can use any class that is in the class path of Hive. You can add jars to class path by executing 'ADD JAR' statements. Please refer to the CLI section Hive Interactive Shell Commands, including Hive Resources, for more information on how to add/delete files from the Hive classpath. Using this, you can register User Defined Functions (UDF's).

Also see Hive Plugins for general information about creating custom UDFs.

Drop Temporary Function

You can unregister a UDF as follows:

DROP TEMPORARY FUNCTION [IF EXISTS] function_name;

In Hive 0.7.0 or later, DROP returns an error if the function doesn't exist, unless IF EXISTS is specified or the configuration variable hive.exec.drop.ignorenonexistent is set to true.

Permanent Functions

In Hive 0.13 or later, functions can be registered to the metastore, so they can be referenced in a query without having to create a temporary function each session.

Create Function

Version information

Icon

As of Hive 0.13.0 (HIVE-6047).

CREATE FUNCTION [db_name.]function_name AS class_name
  [USING JAR|FILE|ARCHIVE 'file_uri' [, JAR|FILE|ARCHIVE 'file_uri'] ];

This statement lets you create a function that is implemented by the class_name. Jars, files, or archives which need to be added to the environment can be specified with the USING clause; when the function is referenced for the first time by a Hive session, these resources will be added to the environment as if ADD JAR/FILE had been issued. If Hive is not in local mode, then the resource location must be a non-local URI such as an HDFS location.

The function will be added to the database specified, or to the current database at the time that the function was created. The function can be referenced by fully qualifying the function name (db_name.funciton_name), or can be referenced without qualification if the function is in the current database.

Drop Function

Version information

Icon

As of Hive 0.13.0 (HIVE-6047).

DROP FUNCTION [IF EXISTS] function_name;

DROP returns an error if the function doesn't exist, unless IF EXISTS is specified or the configuration variable hive.exec.drop.ignorenonexistent is set to true.

[Hive - LanguageManual] Create/Drop/Alter -View、 Index 、 Function的更多相关文章

  1. [Hive - LanguageManual] Create/Drop/Alter Database Create/Drop/Truncate Table

    Hive Data Definition Language Hive Data Definition Language Overview Create/Drop/Alter Database Crea ...

  2. [Hive - LanguageManual] Create/Drop/Grant/Revoke Roles and Privileges / Show Use

    Create/Drop/Grant/Revoke Roles and Privileges Hive Default Authorization - Legacy Mode has informati ...

  3. constraint、index、view(day04)

    回顾: 1.sql99中的表连接 select 字段列表 from 左表 {[inner]|{left|right|full} [outer]} join 右表 on 关联条件; 集合操作 union ...

  4. 闪回之 回收站、Flashback Drop (table、index、trigger等)

    一: Flashback Drop 操作流程 模式一:drop table 后未新建同名表 SQL> create table flashdrop as select * from user_o ...

  5. python中的find、rfind、index、rindex

    find()从左向右寻找子序列的位置,如存在多个相同子序列只返回第一个查找到的位置,如果子序列不存在返回-1 rfind()从右向左寻找子序列的位置..... index()从左向右寻找子序列的位置, ...

  6. Hive 编程之DDL、DML、UDF、Select总结

    Hive的基本理论与安装可参看作者上一篇博文<Apache Hive 基本理论与安装指南>. 一.Hive命令行 所有的hive命令都可以通过hive命令行去执行,hive命令行中仍有许多 ...

  7. Elasticsearch核心技术(2)--- 基本概念(Index、Type、Document、集群、节点、分片及副本、倒排索引)

    Elasticsearch核心技术(2)--- 基本概念 这篇博客讲到基本概念包括: Index.Type.Document.集群,节点,分片及副本,倒排索引. 一.Index.Type.Docume ...

  8. 数据库SQL---数据库、基本表、视图、索引的定义、修改、删除

    1.SQL(结构化查询语言)的组成:数据定义语言DDL.数据操纵语言DML.数据控制语言DCL.其他. 2.SQL语言的功能: 1)数据查询:SELECT 2)数据定义:CREATE   DROP  ...

  9. Mysql索引PRIMARY、NORMAL、UNIQUE、FULLTEXT 区别和使用场合

    索引 数据库的索引就像一本书的目录,能够加快数据库的查询速度. MYSQL索引有四种PRIMARY.INDEX.UNIQUE.FULLTEXT, 其中PRIMARY.INDEX.UNIQUE是一类,F ...

随机推荐

  1. HTTP长连接实现“服务器推”的技术

    HTTP长连接实现“服务器推”的技术快速入门及演示示例 在我的印象里HTTP是一种“无状态的协议”,也就是不知道以前请求的历史,无法保留上一次请求的结果.Cookie的诞生,弥补了这个不足,浏览器可以 ...

  2. player/stage 学习---安装

    环境 ubuntu 14.04 一,工具安装 sudo apt-get install git cmake g++ fltk1.1-dev libjpeg8-dev libpng12-dev libg ...

  3. .net通过获取客户端IP地址反查出用户的计算机名

    这个功能看似很少用到,但又非常实用,看似简单,但又在其中存在很多未知因素造成让人悲痛莫名的负能量... 这是公司内部最近在使用的功能,因为是DHCP,所以有时会根据计算机名做一些统计和权限的设置. 也 ...

  4. [HZAU]华中农业大学第四届程序设计大赛网络同步赛

    听说是邀请赛啊,大概做了做…中午出去吃了个饭回来过掉的I.然后去做作业了…… #include <algorithm> #include <iostream> #include ...

  5. float label 提示

    很多时候,我们写input 都会添加 placeholder 属性,用于提示用户这里该输入什么,怎么输入,但是当用户一旦输入了字符串,该提示就会消失,相信会有人,输入内容后可能会忘记这里要输入的是什么 ...

  6. vs2008 编译时候 自动关闭 问题解决方法

    最近又出现如此让人崩溃的问题.      vs2008在编译程序时候老是莫名其妙的自动退出.卸载重装以后问题仍然存在.      害我一度以为是vs2008的BUG,看网上说的更新BUG.      ...

  7. UVa 10305 (拓扑排序) Ordering Tasks

    题意: 经典的拓扑排序.有n个任务,然后某些任务必须安排在某些任务前面完成,输出一种满足要求的序列. 分析: 拓扑排序用离散里面的话来说就是将偏序关系拓展为全序关系.我们将“小于”这种关系看做一条有向 ...

  8. Struts2配置

    1.      设定server a)      window– preferences – myeclipse – servers – tomcat – 6.x b)      选择tomcat h ...

  9. libogg.so fro android编译方法

    在网站下载源代码http://www.xiph.org/downloads/ 解压然后打开cygwin配置 CXX=arm-linux-androideabi-g++.exe LD=arm-linux ...

  10. zend studio安装xdebug调试工具

    1. 软件准备 登录xdebug 版本检测地址 http://xdebug.org/wizard.php  :将phpinfo产生的数据页面复制到其文本框内,显示类似如下内容: 二.将下载的xdebu ...