Home » Tutorials » Sqoop Tutorials » Sqoop – Eval

Sqoop – Eval

Sqoop - Eval Shout4Education
This chapter describes how to use the Sqoop ‘eval’ tool. It allows users to execute user-defined queries against respective database servers and preview the result in the console. So, the user can expect the resultant table data to import. Using eval, we can evaluate any type of SQL query that can be either DDL or DML statement.

Syntax

The following syntax is used for Sqoop eval command.
$ sqoop eval (generic-args) (eval-args) 
$ sqoop-eval (generic-args) (eval-args)

Select Query Evaluation

Using eval tool, we can evaluate any type of SQL query. Let us take an example of selecting limited rows in the employee table of db database. The following command is used to evaluate the given example using SQL query.
$ sqoop eval 
--connect jdbc:mysql://localhost/db 
--username root  
--query SELECT * FROM employee LIMIT 3
If the command executes successfully, then it will produce the following output on the terminal.
+------+--------------+-------------+-------------------+--------+
| Id   | Name         | Designation | Salary            | Dept   |
+------+--------------+-------------+-------------------+--------+
| 1201 | gopal        | manager     | 50000             | TP     |
| 1202 | manisha      | preader     | 50000             | TP     |
| 1203 | khalil       | php dev     | 30000             | AC     |
+------+--------------+-------------+-------------------+--------+

Insert Query Evaluation

Sqoop eval tool can be applicable for both modeling and defining the SQL statements. That means, we can use eval for insert statements too. The following command is used to insert a new row in the employee table of db database.
$ sqoop eval 
--connect jdbc:mysql://localhost/db 
--username root  
-e INSERT INTO employee VALUES(1207,‘Raju’,‘UI dev’,15000,‘TP’)”
If the command executes successfully, then it will display the status of the updated rows on the console.
Or else, you can verify the employee table on MySQL console. The following command is used to verify the rows of employee table of db database using select’ query.
mysql>
mysql> use db;
mysql> SELECT * FROM employee;
+------+--------------+-------------+-------------------+--------+
| Id   | Name         | Designation | Salary            | Dept   |
+------+--------------+-------------+-------------------+--------+
| 1201 | gopal        | manager     | 50000             | TP     |
| 1202 | manisha      | preader     | 50000             | TP     |
| 1203 | khalil       | php dev     | 30000             | AC     |
| 1204 | prasanth     | php dev     | 30000             | AC     |
| 1205 | kranthi      | admin       | 20000             | TP     |
| 1206 | satish p     | grp des     | 20000             | GR     |
| 1207 | Raju         | UI dev      | 15000             | TP     |
+------+--------------+-------------+-------------------+--------+

Leave a Comment