Skip to content

Latest commit

 

History

History
63 lines (58 loc) · 1.2 KB

create_table.md

File metadata and controls

63 lines (58 loc) · 1.2 KB

创建表

创建管理表

CREATE TABLE IF NOT EXISTS user 
( 
uid string, 
name string, 
sex string, 
age string,
edu string,
addr string
) 
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY '\t' 
STORED AS TEXTFILE;

创建外部表

CREATE EXTERNAL TABLE IF NOT EXISTS user_ext
( 
uid string, 
name string, 
sex string, 
age string,
edu string,
addr string
) 
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY '\t' 
STORED AS TEXTFILE
LOCATION '/user/ifnoelse/user';
  • 外部表LOCATION指定的路径默认为HDFS路径
  • 当然也可以为其他文件系统路径比如s3
create external table kv (key int, values string)  location 's3n://data.s3ndemo.hive/kv';
  • LOCATION 指定的路径应该为目录而不是文件
  • 后续添加到LOCATION目录中的文件会被自动识别
  • OVERWRITE INTO依然可以覆盖外部表中的数据

创建临时表

临时表在hive session结束之后会自动删除

CREATE TEMPORARY TABLE IF NOT EXISTS user_tmp 
( 
uid string, 
name string, 
sex string, 
age string,
edu string,
addr string
) 
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY '\t' 
STORED AS TEXTFILE;

更多创建表的方式

请参考《Apache Hive Essentials》96页