Previously we talked about sqoop import
, now in this article, we will continue on the journey with sqoop export
.
Sqoop Export Common Scenarios
1. export a Hive table to MySQL
|
|
NOTE:
- The
--table
and--export-dir
variables are required for sqoop export. These specify the table to populate in the database, and the directory in HDFS that contains the source data.
2. export a Hive table and only update data in MySQL table
|
|
NOTE:
- we can use
--update-mode updateonly
option to specify that we just want to update existing records and we don’t want insert any new data to the MySQL table.--update-key column_name
variable is to specify the particular column_name that we use for updating existing data
3. export a Hive table and insert and update data in MySQL table
|
|
NOTE
- Different with previous scenario, now we need to use
--update-mode allowinsert
to tell sqoop that we are not only want to update existing data, but inserting new data to the MySQL table
4. export a Hive table and replace null characters
|
|
NOTE:
- we can use
--input-fields-terminated-by
option to setup the input data delimiter in Hive. The default fields delimiter in Hive is\001
. Similarly,--input-lines-terminated-by
option is to setup the lines delimiter and the Hive default value is “\n”. --input-null-string
option is to replace all the null string-typed value to the character we want. Whilst,--input-null-non-string
option is to replace all the null non-string-typed value.