本文匯總了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