Below is a solution from the Apache Sqoop Cookbook.
Saving the Last Imported Value
Problem
Incremental import is a great feature that you use a lot. The shoulder responsibility of remembering the last imported value becomes a problem.
Decision
You can use the built-in Sqoop metastore, which allows you to save all parameters for later reuse. You can create a simple incremental import job with the following command:
sqoop job \ --create visits 3.3. Preserving the Last Imported Value | 27 -- import \ --connect jdbc:mysql://mysql.example.com/sqoop \ --username sqoop \ --password sqoop \ --table visits \ --incremental append \ --check-column id \ --last-value 0
And run it with the --exec parameter :
sqoop job --exec visits
Discussion
Sqoop Metastor is a powerful part of Sqoop that allows you to save definitions of your work and easily run them at any time. Each saved job has a logical name that is used for reference. You can list all saved jobs using the --list :
sqoop job --list
You can delete old job definitions that are no longer needed with the --delete , for example:
sqoop job --delete visits
Finally, you can also view the contents of saved job definitions with the --show parameter , for example:
sqoop job --show visits
The output of the --show command will be in the form of properties. Unfortunately, Sqoop cannot currently rebuild the command line that you used to create the saved job.
The most important benefit of the built-in Sqoop metastar is incremental import. Sqoop automatically converts the last imported value back to the metastor after each successful incremental job. Thus, users do not need to remember the last imported value after each execution; everything is processed automatically.
source share