Sqoop Eval – Commands and Query Evaluation in Sqoop
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.
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
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.
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
Argument | Description |
–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 |
–help | Print usage instructions |
–password-file | Set path for a file containing the authentication password |
-P | Read password from console |
–password <password> | Set authentication password |
–username <username> | Set authentication username |
–verbose | Print more information while working |
–connection-param-file <filename> | Optional properties file that provides connection parameters |
–relaxed-isolation | Set connection transaction isolation to read uncommitted for the mappers. |
b. SQL evaluation arguments
Argument | Description |
-e,–query <statement> | Execute statement in SQL. |
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
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 | Name | Designation | Salary | Dept |
1001 | joe | manager | 50000 | TP |
1002 | chandler | preader | 50000 | TP |
1003 | Ross | php dev | 30000 | AC |
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;
Id | Name | Designation | Salary | Dept |
1001 | joe | manager | 50000 | TP |
1002 | chandler | preader | 50000 | TP |
1003 | Ross | php dev | 30000 | AC |
1004 | Mike | php dev | 30000 | AC |
1005 | Clay | admin | 20000 | TP |
1006 | Henna | Grp des | 20000 | GR |
1007 | Gem | UI dev | 15000 | TP |
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
Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google
Limitation of using query in sqoop
by using sqoop eval it is possible to insert the multiple rows of data ?
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.