Hadoop之Hive完整建表語句

Hive完整建表語句

完整建表語句

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], ... [constraint_specification])]
  [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)

介紹:
[TEMPORARY]:臨時表,當sesssion關閉時,表會被刪除
[EXTERNAL]:外部表,與 [LOCATION hdfs_path]對應,外部表的位置,刪除外部表,文件不會從hdfs上刪除
[PARTITIONED BY (col_name data_type [COMMENT col_comment], …)]:根據後面字段進行分區,對應於hdfs上table級下又的子文件夾,注意,不能是hive中已經存在的字段
[CLUSTERED BY (col_name, col_name, …) [SORTED BY (col_name [ASC|DESC], …)] INTO num_buckets BUCKETS]:分桶,根據後面字段進行分桶,並且排序,對應與mr中的partation,方便數據採樣
[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]
:hive標記這個表是傾斜表, (col_name, col_name, …)指傾斜的列,on後跟隨的是傾斜的值。
[
[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)
]
:ROW FORMAT row_format 定義數據之間的分割符,[STORED AS file_format]指定文件存儲格式,
[TBLPROPERTIES (property_name=property_value, …)] :hive中表內置了一部分屬性,並且可以根據這個進行表屬性的修改
[AS select_statement]:在創建表的時候,導入數據。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章