sqoop Sqoop Import Import subset of RDBMS Table to HDFS


Example

Using --where tag

sqoop import \
--connect <rdbms-jdbc-url> \
--username <username> \
--password <password> \
--table <table-name> \
--where "<condition>"

Example with Mysql:

sqoop import \
--connect jdbc:mysql://mysql.example.com/testdb \
--username root \
--password root \
--table employees \
--where "country = 'INDIA'"

Any special functions, conversions, or even user-defined functions can be used in --where clause.

Using Free Form Query

sqoop import \
--connect <rdbms-jdbc-url> \
--username <username> \
--password <password> \
--query <sql-query> \
--target-dir <target-dir>

Example with Mysql:

sqoop import \
--connect jdbc:mysql://mysql.example.com/testdb \
--username root \
--password root \
--query "SELECT emplyoees.name, \
                address.city \
                FROM emplyoees \
                JOIN address USING(emp_id) \
                WHERE \$CONDITION" \
--taget-dir /dev/data/employees