Sqoop 資料匯出 全量 增量 更新

2021-10-02 21:00:23 字數 2583 閱讀 9429

sqoop支援直接從hive表到rdbms表的匯出操作,也支援hdfs到rdbms表的操作,

當前需求是從hive中匯出資料到rdbms,有如下兩種方案:

ø 從hive表到rdbms表的直接匯出:

該種方式效率較高,但是此時相當於直接在hive表與rdbms表的資料之間做全量、增量和更新對比,當hive表記錄較大時,或者rdbms有多個分割槽表時,無法做精細的控制,因此暫時不考慮該方案。

ø 從hdfs到rdbms表的匯出:

該方式下需要先將資料從hive表匯出到hdfs,再從hdfs將資料匯入到rdbms。雖然比直接匯出多了一步操作,但是可以實現對資料的更精準的操作,特別是在從hive表匯出到hdfs時,可以進一步對資料進行字段篩選、字段加工、資料過濾操作,從而使得hdfs上的資料更「接近」或等於將來實際要匯入rdbms表的資料。在從hdfs匯入rdbms時,也是將乙個「小資料集」與目標表中的資料做對比,會提高匯出速度。示意圖如下所示:

ø 應用場景:將hive表中的全部記錄(可以是全部欄位也可以部分字段)匯出到目標表。

ø 實現邏輯:

ø 使用限制:目標表中不能有與hive中相同的記錄,一般只有當目標表為空表時才使用該模式進行首次資料匯出。

ø 引數:源表、目標表、匯出字段(select的字段)、對映關係(–column後的引數)

ø 適用的資料庫:oracle、db2、sql server、pg、mysql

ø 應用場景:將hive表中的增量記錄以及有修改的記錄同步到目標表中。

ø 實現邏輯:

ø 使用限制:update-key可以是多個字段,但這些欄位的記錄都應該是未被更新過的,若該引數指定的字段有更新,則對應記錄的更新不會被同步到目標表中。

ø 適用的資料庫:oracle、sql server、mysql

ø 應用場景:將hive表中的有更新的記錄同步到目標表。

ø 實現邏輯:

ø 使用限制:update-key可以是多個字段,但這些欄位的記錄都應該是未被更新過的,若該引數指定的字段有更新,則對應記錄的更新不會被同步到目標表中。

ø 適用的資料庫:oracle、db2、sql server、pg、mysql

hql示例:insert overwrite  directory 『/user/root/export/test』 row format delimited fields terminated by 『,』 stored as textfile select f1,f2,f3 from ; 

sqoop指令碼:sqoop export --connect jdbc:mysql://localhost:3306/wht --username root --password cloudera --table --fields-terminated-by ',' --columns f1,f2,f3 --export-dir /user/root/export/test

hql示例:insert overwrite  directory 『/user/root/export/test』 row format delimited fields terminated by 『,』 stored as textfile select f1,f2,f3 from  where ; 

sqoop指令碼:sqoop export --connect jdbc:mysql://localhost:3306/wht --username root --password cloudera --table --fields-terminated-by 『,』 --columns f1,f2,f3 --update-key f4 --update-mode allowinsert --export-dir /user/root/export/test

hql示例:insert overwrite  directory 『/user/root/export/test』 row format delimited fields terminated by 『,』 stored as textfile select f1,f2,f3 from  where ; 

sqoop指令碼:sqoop export --connect jdbc:mysql://localhost:3306/wht --username root --password cloudera --table --fields-terminated-by 『,』 --columns f1,f2,f3 --update-key f4 --update-mode updateonly --export-dir /user/root/export/test

Sqoop 資料匯出 全量 增量 更新

sqoop支援直接從hive表到rdbms表的匯出操作,也支援hdfs到rdbms表的操作,當前需求是從hive中匯出資料到rdbms,有如下兩種方案 從hive表到rdbms表的直接匯出 該種方式效率較高,但是此時相當於直接在hive表與rdbms表的資料之間做全量 增量和更新對比,當hive表記...

sqoop全增量匯出到mysql

全量匯出 hql示例 insert overwrite directory user root export test row format delimited fields terminated by stored as textfile select f1,f2,f3 from sqoop指令碼...

Sqoop的全量匯入和增量匯入

增量匯入 2.lastmodify方式 基於時間列 sqoop import connect jdbc mysql username scfl password scfl123 query select from test table where conditions target dir user...