Apache Sqoop Eval tool is used to run user-defined SQL queries against a database and print results on the console so that a user can review the content of the table before performing Import operation. We can use Eval to evaluate DDL and DML operations.
Eval Syntax
The following is the syntax of Apache Sqoop Eval.
$ sqoop eval (generic-args) (args)Eval Example
Let us see some examples to select, insert and update rows using the Apache Sqoop Eval tool from the “employee” table that is present under the “userdata” database in MySQL.
Select Evaluation
We will use the below command to fetch rows from the “employee” table and print the records on the terminal.
Command:
cloudduggu@ubuntu:~$ sqoop eval --connect jdbc:mysql://localhost/userdata?serverTimezone=UTC --username root--password cloudduggu --query "select * from employee"
Output:
We can see all rows are printed for the “employee” table.
Insert Evaluation
We will use the below command to insert a row in the “employee” table and print the output on the terminal.
Command:
cloudduggu@ubuntu:~$ sqoop eval --connect jdbc:mysql://localhost/userdata?serverTimezone=UTC --username root--password cloudduggu --query "update employee set empname='cloudduggu' where empid=1010;"
Output:
We can see one row is inserted in the “employee” table.
Update Evaluation
We will use the below command to update the row in the “employee” table and print the output on the terminal.
Command:
cloudduggu@ubuntu:~$ sqoop eval --connect jdbc:mysql://localhost/userdata?serverTimezone=UTC --username root--password cloudduggu --query "update employee set empname='cloudduggu' where empid=1010;"
Output:
We can see one row is updated in the “employee” table.