码迷,mamicode.com
首页 > 其他好文 > 详细

hive DDL

时间:2016-10-31 13:11:46      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:target   bucket   type   create   int   nbsp   user   数据库   trunc   

官网地址:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL

              https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML

Hive DDL 包括下面内容

  • CREATE DATABASE/SCHEMA, TABLE, VIEW, FUNCTION, INDEX
  • DROP DATABASE/SCHEMA, TABLE, VIEW, INDEX
  • TRUNCATE TABLE
  • ALTER DATABASE/SCHEMA, TABLE, VIEW
  • MSCK REPAIR TABLE (or ALTER TABLE RECOVER PARTITIONS)
  • SHOW DATABASES/SCHEMAS, TABLES, TBLPROPERTIES, VIEWS, PARTITIONS, FUNCTIONS, INDEX[ES], COLUMNS, CREATE TABLE
  • DESCRIBE DATABASE/SCHEMA, table_name, view_name

创建数据库Create Database:

CREATE (DATABASE|SCHEMA) [IF NOT EXISTS] database_name
  [COMMENT database_comment]
  [LOCATION hdfs_path]
  [WITH DBPROPERTIES (property_name=property_value, ...)];
DATABASE 和 SCHEMA具有相同的含义,他们是可以互换的
create database if not exists db_test comment "this is a test database";

删除数据库Drop Database

DROP (DATABASE|SCHEMA) [IF EXISTS] database_name [RESTRICT|CASCADE];
RESTRICT:如果数据库不为空则删除失败,CASCADE数据库不为空也可以删除

使用数据库Use Database

USE database_name;
USE DEFAULT;

创建表Create

语法:

CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.]table_name    -- (Note: TEMPORARY available in Hive 0.14.0 and later)
  [(col_name data_type [COMMENT col_comment], ...)]
  [COMMENT table_comment]
  [PARTITIONED BY (col_name data_type [COMMENT col_comment], ...)]
  [CLUSTERED BY (col_name, col_name, ...) [SORTED BY (col_name [ASC|DESC], ...)] INTO num_buckets BUCKETS]
  [SKEWED BY (col_name, col_name, ...)                  -- (Note: Available in Hive 0.10.0 and later)]
     ON ((col_value, col_value, ...), (col_value, col_value, ...), ...)
     [STORED AS DIRECTORIES]
  [
   [ROW FORMAT row_format] 
   [STORED AS file_format]
     | STORED BY ‘storage.handler.class.name‘ [WITH SERDEPROPERTIES (...)]  -- (Note: Available in Hive 0.6.0 and later)
  ]
  [LOCATION hdfs_path]
  [TBLPROPERTIES (property_name=property_value, ...)]   -- (Note: Available in Hive 0.6.0 and later)
  [AS select_statement];   -- (Note: Available in Hive 0.5.0 and later; not supported for external tables)
 
CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.]table_name
  LIKE existing_table_or_view_name
  [LOCATION hdfs_path];

 

CREATE TABLE page_view(viewTime INT, userid BIGINT,
     page_url STRING, referrer_url STRING,
     ip STRING COMMENT ‘IP Address of the User‘)
 COMMENT ‘This is the page view table‘
 PARTITIONED BY(dt STRING, country STRING)
 STORED AS SEQUENCEFILE;

 

 CREATE TABLE empty_key_value_store
  LIKE page_view;

 

清空表中的数据Truncate Table

 

TRUNCATE TABLE table_name [PARTITION partition_spec];

  

删除表Drop

DROP TABLE [IF EXISTS] table_name [PURGE]; 

  

 

 

hive DDL

标签:target   bucket   type   create   int   nbsp   user   数据库   trunc   

原文地址:http://www.cnblogs.com/heml/p/6015359.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!