关于导入数据时有一个关于日期类型的数据的警告:
sqoop 在进行数据抽取是,即 mysql 导入 hive 时

mysql 中关于时间的数据类型是 timestamp

hive 的表是 sqoop 创建的,它的时间类型是 string

所以有一个警告。
解决办法:
因为我们从mysql导入数据到hive的时候,hive表是自己创建的,那么就会出现mysql的字段是timestamp,但是导入hive的时候变成了bigint。
为了解决这个问题:
1、自己手动创建hive表,这样创作的表数据类型更加精准,特别是一些精度要求非常高的字段
2、可以在sqoop导入的时候,指定数据类型,以上sqoop就是指定了数据类型,使用了
--map-column-java updated_at=java.sql.Timestamp \
--map-column-hive updated_at=Timestamp \
示例:
sqoop import \
--driver com.mysql.cj.jdbc.Driver \
--connect jdbc:mysql://hadoop11:3306/jrxd?characterEncoding=UTF-8 \
--username root \
--password 123456 \
--query 'select * from dict_product where DATE_FORMAT(updated_at,"%Y-%m-%d") = "2024-06-30" and $CONDITIONS' \
--target-dir /tmp/dict_product \
--map-column-java updated_at=java.sql.Timestamp \
--map-column-hive updated_at=Timestamp \
--delete-target-dir \
--split-by id \
--num-mappers 1 \
--hive-import \
--fields-terminated-by "\t" \
--hive-overwrite \
--hive-database finance \
--hive-table ods_dict_product \
--null-non-string '\\N' \
--null-string '\\N'
如果你想测试这个效果,需要先删除之前的表,再次创建时才会看到效果。
4432

被折叠的 条评论
为什么被折叠?



