本文汇总了Sqoop使用时的常见问题。
导入RDS数据至EMR时,时间字段显示提前8小时如何处理?
-
问题描述:
-
例如,在云数据库RDS数据源中,数据表test_table中包含时间戳(TIMESTAMP)字段。在DMS中查询RDS源表
test_table的数据,结果包含id和applied_at两列,共5条记录,applied_at字段的值分别为 2024-06-14 10:08:04 至 2024-06-18 10:08:04(每天递增一天,时间均为 10:08:04)。 -
您可以执行以下命令,导入test_table中的数据至HDFS。
sqoop import \ --connect jdbc:mysql://rm-2ze****341.mysql.rds.aliyuncs.com:3306/s***o_sqoop_db \ --username s***o \ --password ****** \ --table test_table \ --target-dir /user/hadoop/output \ --delete-target-dir \ --direct \ --split-by id \ --fields-terminated-by '|' \ -m 1 -
查询导入结果。
查询结果显示,HDFS中导入数据的时间字段显示提前8小时。
[root@master-1-1(xxx) ~]# hdfs dfs -cat /user/hadoop/output/part-m-00000 1 2024-06-18 02:08:04 2 2024-06-17 02:08:04 3 2024-06-16 02:08:04 4 2024-06-15 02:08:04 5 2024-06-14 02:08:04
-
-
解决方法:在使用TIMESTAMP字段导入数据至HDFS时,请删除--direct参数。
sqoop import \ --connect jdbc:mysql://rm-2ze****341.mysql.rds.aliyuncs.com:3306/s***o_sqoop_db \ --username s***o \ --password ****** \ --table test_table \ --target-dir /user/hadoop/output \ --delete-target-dir \ --split-by id \ --fields-terminated-by '|' \ -m 1查询结果显示正常。
[root@master-1-1(xxx) ~]# hdfs dfs -cat /user/hadoop/output1/part-m-00000 1 2024-06-18 10:08:04.0 2 2024-06-17 10:08:04.0 3 2024-06-16 10:08:04.0 4 2024-06-15 10:08:04.0 5 2024-06-14 10:08:04.0