hive 创建表详解

时间:2025-04-16 08:17:24
hive> create table studyinfo(id int, age int)
    > row format delimited
    > fields terminated by ','
    > stored as textfile;
OK

Time taken: 2.666 seconds


[ROW FORMATDELIMITED]关键字,是用来设置创建的表在加载数据的时候,支持的列分隔符;

create table  user_info (user_id int, cid string, ckid string, username string) 

row format delimited 

fields terminated by '\t'

 lines terminated by '\n';

导入数据表的数据格式是:字段之间是tab键分割,行之间是断行。

及要我们的文件内容格式:

100636  100890  c5c86f4cddc15eb7        yyyvybtvt
100612  100865  97cc70d411c18b6f        gyvcycy
100078  100087  ecd6026a15ffddf5        qa000100



[STORED AS file_format]关键字是用来设置加载数据的数据类型。

Hive本身支持的文件格式只有:TextFile,Sequence File。

如果文件数据是纯文本,可以使用 [STORED AS TEXTFILE]。

如果数据需要压缩,使用[STORED AS SEQUENCE] 。

通常情况,只要不需要保存序列化的对象,我们默认采用[STORED AS TEXTFILE]。