This topic summarizes common Sqoop issues.
Timestamp shifts 8 hours after import
-
Problem
-
For example, the test_table table in an ApsaraDB RDS data source contains a timestamp field. When you query the source table
test_tablein DMS, the result contains five records with theidandapplied_atcolumns. The values in theapplied_atcolumn range from 2024-06-14 10:08:04 to 2024-06-18 10:08:04 (incremented by one day, with the time fixed at 10:08:04). -
Run the following command to import data from test_table to 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 -
Query the import result.
The result shows that the timestamp field in HDFS is shifted back by 8 hours.
[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
-
-
Solution: When importing data that contains a timestamp field to HDFS, remove the --direct argument.
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 1The query result now shows the correct values.
[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