背景:
实操:
先准备一张临时表,其中数据如下(其中sex和class的内容为中文)
create table tmp(
id int ,
name string ,
score int ,
sex string ,
class string
) row format delimited fields terminated by ',' ;
新建分区表stu_p
create table stu_p(
id int ,
name string ,
score int
)
partitioned by(year string ,month string )
row format delimited fields terminated by ',' ;
动态分区的方法将数据插入到stu_p
insert into table stu_p select * from tmp ;
或者
insert into table stu_p select id ,name ,score ,sex,class from tmp ;
报错如下:
FAILED: Execution Error, return code 1 from
org.apache.hadoop.hive.ql.exec.MoveTask. Exception when loading 6 in
table stu_p with
loadPath=hdfs://localhost:9000/user/hive/warehouse/db1.db/stu_p/.hive-staging_hive_2022-07-28_11-40-02_443_3225396161542468090-1/-ext-10000
可见MR任务是没有问题的,只是移动数据到hdfs对应目录时出错,经过分析才发现,因为分区字段里sex和class的内容是中文,在生成中文的目录时出错,故将中文字段改成英文后,可使用动态分区的方法成功插入
修改tmp表数据如下:
重新执行插入sql,可顺利插入
insert into table stu_p select * from tmp ;
结论(重要):
1、分区表的分区字段内容里最好不用中文;
2、若出现上述报错,可考虑修改元数据保存格式问题,我的元数据保存在mysql里,可尝试修改mysql里Metastroe所在库的字符编码(目前正研究中) ;
----本文待更新
更改字符编码参看https://blog.csdn.net/bbvjx1314/article/details/103172123/