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 ' ' location '/hive/dw';
注意:location必须是个目录,而不是文件!
t表:
a,aaa,bbb2,ccc,dddadfd,eee,fff
创建T表:
create EXTERNAL table IF NOT EXISTS t (id int,s1 string,s2 string)ROW FORMAT DELIMITEDFIELDS TERMINATED BY ','location '/user/hive/warehouse/t';
查询:
hive>> select * from t;OKNULL bbb NULL2 ccc dddNULL eee fffTime taken: 2.051 seconds, Fetched: 3 row(s)
如果数据类型不对,则hive表示为NULL