問題1:
用公司的大數(shù)據(jù)平臺(tái)(DataX)導(dǎo)數(shù),已經(jīng)開發(fā)上線一個(gè)多月的一批報(bào)表,突然有同事說有個(gè)報(bào)表數(shù)據(jù)不準(zhǔn)。出在時(shí)間字段上。
分析:
1、先看了原數(shù)據(jù)MySQL字段類型為datetime,目標(biāo)字段為timestamp類型;
2、經(jīng)發(fā)現(xiàn)所有時(shí)間的差距都是8小時(shí),懷疑是因?yàn)闀r(shí)區(qū)轉(zhuǎn)換的原因;
3、對(duì)比其他表,看看是大范圍現(xiàn)象還是特殊情況,發(fā)現(xiàn)其他的同樣情況字段的一樣沒有問題,也有改變?yōu)閟tring字段類型的也沒有問題;
測(cè)試
MySQL 數(shù)據(jù)信息
MySQL表名:test
MySQL字段類型如下:
field_name | type |
---|---|
id | int |
name | varchar |
creat_day_time | datetime |
create_day | date |
create_time | time |
create_time_stamp | timestamp |
-----測(cè)試數(shù)據(jù)如下
id name create_day_time create_day create_time create_time_stamp
1 xiaoming 2023-04-10 14:20:42 2023-04-10 14:20:42 2023-04-10 14:20:42
2 xiaohong 2023-04-21 14:21:02 2023-04-21 14:21:02 2023-04-21 14:21:02
HIVE數(shù)據(jù)信息
hive中用 text 文件格式存儲(chǔ)
hive 表名:test_text
field_name | type |
---|---|
id | int |
name | string |
creat_day_time | string |
create_day | string |
create_time | string |
create_time_stamp | string |
-----hive 表中的數(shù)據(jù):
id name create_day_time create_day create_time create_time_stamp
1 xiaoming 2023-04-10 14:20:42 2023-04-10 14:20:42 2023-04-10 14:20:42
2 xiaohong 2023-04-21 14:21:02 2023-04-21 14:21:02 2023-04-21 14:21:02
與mysql表里面數(shù)據(jù)一致;
hive中用 parquet(orc) 列式文件格式存儲(chǔ)
hive表名:test_parquet
導(dǎo)入hive命令:
field_name | type |
---|---|
id | int |
name | string |
creat_day_time | string |
create_day | string |
create_time | string |
create_time_stamp | string |
-----hive 表中的數(shù)據(jù):
id name create_day_time create_day create_time create_time_stamp
1 xiaoming 1681107642000 1681056000000 22842000 1681107642000
2 xiaohong 1682058062000 1682006400000 22862000 1682058062000
結(jié)論:
1、sqoop(DataX) 導(dǎo) mysql 到 hive以text文件格式存儲(chǔ)時(shí),mysql時(shí)間類型:datetime,date,time,timestamp 會(huì)被轉(zhuǎn)成 hive 的 string 類型,值保存格式化后的時(shí)間字符串
2、sqoop(DataX) 導(dǎo) mysql 到 hive以parquet(orc)l列式文件格式存儲(chǔ)時(shí),mysql時(shí)間類型:datetime,date,time,timestamp 會(huì)被轉(zhuǎn)成 hive的相應(yīng)類型,值保存時(shí)間戳
解決方法
hive表存儲(chǔ)格式為:行式存儲(chǔ)(text)格式,hive表相應(yīng)字段(mysql里面datetime字段)設(shè)置為string類型;
問題2:
mysql表中字段類型是tinyint(1),同步到hive中,也會(huì)顯示出布爾類型,就是true和false。
官網(wǎng)解釋如下:
Mysql中存在tinyint(1)時(shí),在數(shù)據(jù)導(dǎo)入到HDFS時(shí),該字段默認(rèn)會(huì)被轉(zhuǎn)化為boolean數(shù)據(jù)類型,導(dǎo)致數(shù)據(jù)內(nèi)容丟失(都變?yōu)镹ULL)。
解決方法
1、可以在mysql中在建立一張表,將新建立的表修改為int類型,之后在進(jìn)行同步。文章來源:http://www.zghlxwxcb.cn/news/detail-781582.html
2、修改sqoop的同步腳本。
解決方案:
在–connect參數(shù)后的jdbc連接上添加參數(shù):tinyInt1isBit=false
注意:
若有多個(gè)參數(shù),需要使用雙引號(hào)將整個(gè)參數(shù)值括起來文章來源地址http://www.zghlxwxcb.cn/news/detail-781582.html
如:–connect " jdbc:mysql://ip:3306/db?serverTimezone=Asia/Shanghai&tinyInt1isBit=false "
到了這里,關(guān)于sqoop(DataX)-MySQL導(dǎo)入HIVE時(shí)間格問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!