Understanding Sqoop Eval Command

In this blog, we will understand Sqoop’s eval command. Sqoop’s eval command parameter allows a user to perform DDL and DML queries against the DB and previews the results in the console. We will see and understand two evaluations,

  1. Select Query Eval
  2. Insert Query Eval

 

Assumptions:

  • I am assuming that you are using MySQL as the DB source for this example whose username is root and password is 123456.
  • In MySQL there exists a table named emp inside hadoopbook db.

Lets first understand Select Query Evaluation. Perform the following command,

sqoop eval --connect jdbc:mysql://192.168.149.152:3306/hadoopbook --username root --password 123456 --query “select * from emp”
17/06/10 01:29:17 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6
17/06/10 01:29:17 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
17/06/10 01:29:18 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
---------------------------------------------------------------------------
| eid         | fname                | lname                | esal        |
---------------------------------------------------------------------------
| 1           | Prashant             | Nair                 | 100000      |
| 2           | Utkarsha             | Nair                 | 100000      |
| 3           | Akhilesh             | Kumar                | 50000       |
---------------------------------------------------------------------------

Thus the above command helps to perform select query through Sqoop. Now lets us see how to perform insert operation using Sqoop. Assuming there exists emp table inside hadoopbook database, lets insert one record.

sqoop eval --connect jdbc:mysql://hadoopvm:3306/hadoopbook --username root --password 123456 --query "insert into emp values (4,'Premanand','Nair',400000)"
17/06/10 01:31:17 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6
17/06/10 01:31:17 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
17/06/10 01:31:17 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
17/06/10 01:31:18 INFO tool.EvalSqlTool: 1 row(s) updated.

The above command was able to insert the data. To verify the insert, you can try the previous command.

sqoop eval –connect jdbc:mysql://192.168.149.152:3306/hadoopbook –username root –password 123456 –query “select * from emp”

Hope you liked this Sqoop Trick !

Prashant Nair

Bigdata Consultant | Author | Corporate Trainer | Technical Reviewer Passionate about new trends and technologies. More Geeky. Contact me for training and consulting !!!

Leave a Reply

Your email address will not be published. Required fields are marked *