问题描述
服务器系统版本: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 表中的数据:
结论
- sqoop 导 mysql 到 hive以text文件格式存储时,mysql时间类型:datetime,date,time,timestamp 会被转成 hive 的 string 类型,值保存格式化后的时间字符串
- sqoop 导 mysql 到 hive以test_parquet文件格式存储时,mysql时间类型:datetime,date,time,timestamp 会被转成 hive 的 bigint 类型,值保存时间戳