Sqoop Eval – Commands and Query Evaluation in Sqoop

1. Objective

Basically, to quickly run simple SQL queries against a database, we use Sqoop Eval tool in Sqoop. However, there are many more purposes Sqoop Eval offers. So, this Sqoop tutorial aims the whole concept of Sqoop Eval. After its introduction, we will also cover its syntax and its commands. Moreover, we will also cover its examples to understand it better.

Introduction of Sqoop Eval

Sqoop Eval – Introduction

2. What is Sqoop Eval?

Basically, to quickly run simple SQL queries against a database server. Also to preview the result in the console, we use Sqoop Eval tool. Hence, as a user, we can expect the resultant table data to Sqoop import. Moreover, we can evaluate any type of SQL query. Either DDL or DML statement by using eval.
Follow this link to know about Sqoop Export

Get the most demanding skills of IT Industry - Learn Hadoop

3. Why Sqoop Eval?

As we discussed above, the main purpose of eval tool is it allows users to quickly run simple SQL queries against a database. Afterwards, results are printed to the console. Also, it allows users to preview their Sqoop import queries to ensure they import the data they expect.
Note: Basically, for evaluation purpose only, the eval tool is provided. Moreover, we can only use it to verify database connection from within the Sqoop. Also, to test simple queries. Likewise, we can not use Sqoop tool in production workflows.

4. Sqoop Eval Syntax

$ sqoop eval (generic-args) (eval-args)
$ sqoop-eval (generic-args) (eval-args)
However, Sqoop eval arguments can be entered in any order with respect to one another, but the Hadoop generic arguments must precede any eval arguments only.

a. Common arguments

ArgumentDescription
–connect <jdbc-uri>Specify JDBC connect string
–connection-manager <class-name>Specify connection manager class to use
–driver <class-name>Manually specify JDBC driver class to use
–hadoop-mapred-home <dir>Override $HADOOP_MAPRED_HOME
–helpPrint usage instructions
–password-fileSet path for a file containing the authentication password
-PRead password from console
–password <password>Set authentication password
–username <username>Set authentication username
–verbosePrint more information while working
–connection-param-file <filename>Optional properties file that provides connection parameters
–relaxed-isolationSet connection transaction isolation to read uncommitted for the mappers.

b. SQL evaluation arguments

ArgumentDescription
-e,–query <statement>Execute statement in SQL.

5. Sqoop Eval Commands

a. For changing the directory to /usr/local/hadoop/sbin
$ cd /usr/local/hadoop/sbin
b. To Start all Hadoop daemons
$ start-all.sh
c. The JPS(java virtual machine Process Status Tool) tool is limited to reporting information on JVMs for which it has the access Permissions
$ jps
d. Change the directory to /usr/local/Sqoop/bin
$ cd /usr/local/sqoop/bin

6. Select Query Evaluation in Sqoop Eval

As we discussed earlier, we can evaluate any type of SQL query by using eval tool. For example,  we are selecting limited rows in the employee table of DB database. Now, to evaluate the given example using SQL query we will use the following command.
$ sqoop eval \
–connect jdbc:mysql://localhost/db \
–username root \
–query “SELECT * FROM employee LIMIT 3”
Moreover, it will produce the following output on the terminal, if the command executes successfully.

Id NameDesignationSalary Dept
1001joemanager 50000TP
1002chandlerpreader50000TP
1003Rossphp dev30000AC
Hadoop Quiz

7. Insert Query Evaluation

Basically, for both modeling and defining the SQL statements, Sqoop eval tool can be applied. It refers that for insert statements too, we can use eval tool. Likewise, to insert a new row in the employee table of DB database we use the following command.
$ sqoop eval \
–connect jdbc:mysql://localhost/db \
–username root \
-e “INSERT INTO employee VALUES(1007,‘Gem’,‘UI dev’,15000,‘TP’)”
Moreover, it will display the status of the updated rows on the console, if the command executes successfully.
However, we can also verify the employee table on MySQL console. Moreover, using select’ query we can verify the rows of employee table of DB database with the following Sqoop Eval command:
mysql>
mysql> use DB;
mysql> SELECT * FROM employee;

IdName DesignationSalary Dept
1001joemanager 50000TP
1002chandlerpreader50000TP
1003Rossphp dev30000AC
1004Mikephp dev30000AC
1005Clayadmin20000TP
1006HennaGrp des20000GR
1007GemUI dev15000TP

8. Conclusion

As a result, we have seen the whole concept of Sqoop Eval. Also, we have seen Sqoop Eval purpose and its syntax. Moreover, we have seen all Sqoop Eval Commands. Afterwards, we have also covered Select Query Evaluation and Insert Query Evaluation. However, still, if you feel anything is missing or if you want to ask any query regarding, feel free to ask in the comment section. We Ensure we will definitely get back to you.
Learn Validation in Sqoop & Feature of Sqoop
For reference

3 Responses

  1. Naman says:

    Limitation of using query in sqoop

  2. k.krishna mohan says:

    by using sqoop eval it is possible to insert the multiple rows of data ?

  3. Pooja pawar says:

    I want to run multiple queries from. Sql file using sqoop eval. Those queries are for duplicate check on target tables. But sqoop eval is not taking the having condition. Can you please help.

Leave a Reply

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.