hive创建外部表
Create [EXTERNAL] TABLE [IF NOT EXISTS] table_name
[(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]
[ROW FORMAT row_format]
[STORED AS file_format]
[LOCATION hdfs_path]
例子:
create EXTERNAL table IF NOT EXISTS userInfo (id int,sex string, age int, name string, email string,sd string, ed string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' location '/hive/dw';
注意:location必须是个目录,而不是文件!
t表:
a,aaa,bbb
2,ccc,ddd
adfd,eee,fff
创建T表:
create EXTERNAL table IF NOT EXISTS t (
id int,
s1 string,
s2 string
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
location '/user/hive/warehouse/t';
查询:
hive>
> select * from t;
OK
NULL bbb NULL
2 ccc ddd
NULL eee fff
Time taken: 2.051 seconds, Fetched: 3 row(s)
如果数据类型不对,则hive表示为NULL