sqoop系列-MySQL導入HIVE時間格問題

問題描述

服務器系統版本:centos 7.2
cdh 版本:cdh5.9.0
hadoop 版本:2.6.0+cdh5.9.0
sqoop 版本:1.4.6+cdh5.9.0
hive 版本:1.1.0+cdh5.9.0
MySQL 版本:5.5

今天早上在做 sqoop MySQL 導入hive數據測試時發現 MySQL 中datetime和timestamp類型的數據導入hive時,選擇不同的文件存儲格式,會導致導入hive 後字段類型不一致。針對 MySQL 時間類型:datetime,date,time,timestamp 做了如下測試,
備註:涉及敏感信息的的變量,使用${xxxx} 代替


MySQL 數據信息

MySQL表名:test
MySQL字段類型如下:
這裏寫圖片描述

測試數據如下:
這裏寫圖片描述


HIVE數據信息

hive中用 text 文件格式存儲
hive 表名:test_text
導入hive命令:

sudo -u cloudera-scm sqoop import  --connect  ${connect}  --username ${username}  --password ${password} --table test --as-textfile --hive-import --hive-overwrite --delete-target-dir --hive-drop-import-delims --hive-table test_text 

hive 表的字段類型如下:
這裏寫圖片描述

hive 表中的數據:
這裏寫圖片描述

hive中用 parquet 文件格式存儲
hive表名:test_parquet
導入hive命令:

sudo -u cloudera-scm sqoop import  --connect  ${connect} --username ${username}  --password ${password} --table test  --as-parquetfile --hive-import --hive-overwrite --delete-target-dir --hive-drop-import-delims --hive-table test_parquet

hive 表的字段類型如下:
這裏寫圖片描述

hive 表中的數據:
這裏寫圖片描述


結論

  1. sqoop 導 mysql 到 hive以text文件格式存儲時,mysql時間類型:datetime,date,time,timestamp 會被轉成 hive 的 string 類型,值保存格式化後的時間字符串
  2. sqoop 導 mysql 到 hive以test_parquet文件格式存儲時,mysql時間類型:datetime,date,time,timestamp 會被轉成 hive 的 bigint 類型,值保存時間戳
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章