数据文件
假设数据文件为student1.txt和student2.txt,记录两个班的学生信息。
建表语句
在hive中创建分区表
-- 创建分区表
create table student_partition (
id int,
name string,
age int
)partitioned by (class_name string)
row format delimited fields terminated by ',';
导入数据
-- 本地导入
load data local inpath '/root/student1.txt' into table student_partition partition(class_name='class1');
-- hdfs导入
load data inpath 'hdfs://localhost:9000/input/tables/student2.txt' into table student_partition partition (class_name='class2');
值得注意的是,本地文件导入不会删除本地的原文件,但在hdfs上导入则会将原hdfs路径下的文件删除,即本地导入是复制文件,而hdfs是移动文件。