create table t_sz01(id int,name string) row format delimited fields terminated by ',';
create table if not exists mytable(sid int,sname string) row format delimited fields terminated by ',' stored as textfile;
create external table if not exists extable(sid int,sname string) row format delimited fields terminated by ',' location 'hdfs://192.168.76.90:9000/user/hive/warehouse/'
#导入数据into table
load data local inpath '/home/hadoop/file/sz.dat' into table mytable;
#覆盖数据OVERWRITE table
load data local inpath '/home/hadoop/file/sz.dat' overwrite table mytable;
分区建表分为2种,一种是单分区,也就是说在表文件夹目录下只有一级文件夹目录。另外一种是多分区,表文件夹下出现多文件夹嵌套模式。
单分区建表语句:单分区表,按天分区,在表结构中存在id,content,dt三列
create table test_table (id int, content string) partitioned by (dt string) row format delimited fields terminated by ',';
导入数据:
load data inpath '/home/hadoop/file/SZ20180712.dat' into table test_table partition(dt='20180712');
load data inpath 'home/hadoop/file/SZ20180715.dat' into table test_table partition(dt='20180715');
双分区建表语句:双分区表,按天和小时分区,在表结构中新增加了dt和hour两列
create table test_table_2 (id int, content string) partitioned by (dt string, hour string);