sqoop - Sqoop Eval - apache sqoop - sqoop tutorial - sqoop hadoop



What is Sqoop Eval?

  • Sqoop eval tool can be applicable for both modeling and defining the SQL statements.
  • 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)
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team

Sqoop Eval Command With Example

  • The sqoop eval command 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.

Step 1 - Change the directory to /usr/local/hadoop/sbin

$ cd /usr/local/hadoop/sbin
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team

Step 2 - Start all hadoop daemons.

$ start-all.sh
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team

Step 3 - The JPS (Java Virtual Machine Process Status Tool) tool is limited to reporting information on JVMs for which it has the access permissions

            $ jps
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team

Step 4 - Change the directory to /usr/local/sqoop/bin

$ cd /usr/local/sqoop/bin
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team

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 wikitechy_employee table of db database.
  • The below command is used to evaluate the given example using SQL query.
$ sqoop eval \
--connect jdbc:mysql://localhost/db \
--username root \ 
--query “SELECT * FROM wikitechy_employee LIMIT 3”
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team
  • After the execution of the command successfully, then it will produce the below output on the terminal.

+------+--------------+-------------+-------------------+--------+
| Id   | Name         | Designation | Salary            | Dept   |
+------+--------------+-------------+-------------------+--------+
| 1201 | venkat       | manager     | 50000             | TP     |
| 1202 | manisha      | preader     | 50000             | TP     |
| 1203 | nila         | 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.
  • Using the below command to insert a new row in the wikitechy_employee table of db database.
$ sqoop eval \
--connect jdbc:mysql://localhost/db \
--username root \ 
-e “INSERT INTO wikitechy_employee VALUES(1207,‘Raju’,‘UI dev’,15000,‘TP’)”
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team
  • After the execution of the command successfully, then it will display the status of the updated rows on the console.
  • Otherwise, you can verify the wikitechy_employee table on MySQL console.
  • Using the below command to verify the rows of wikitechy_employee table of db database using select’ query.
mysql>
mysql> use db;
mysql> SELECT * FROM wikitechy_employee;
+------+--------------+-------------+-------------------+--------+
| Id   | Name         | Designation | Salary            | Dept   |
+------+--------------+-------------+-------------------+--------+
| 1201 | venkat       | manager     | 50000             | TP     |
| 1202 | manisha      | preader     | 50000             | TP     |
| 1203 | nila         | php dev     | 30000             | AC     |
| 1204 | prasanth     | php dev     | 30000             | AC     |
| 1205 | kranthi      | admin       | 20000             | TP     |
| 1206 | harish p     | grp des     | 20000             | GR     |
| 1207 |john          | UI dev      | 15000             | TP     |
+------+--------------+-------------+-------------------+--------+
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team


Related Searches to Sqoop - Eval