Apache Sqoop Eval Arguments and Examples

For running any simple SQL queries against the database, the Sqoop Eval is used in Apache Sqoop. In this Sqoop Eval article, we will study each and everything about the Sqoop Eval. The article first explains what Sqoop Eval is.

Later on, in this article, you will explore Sqoop Eval syntax and commands. We had explained Sqoop Eval with an example to make it easier for you to understand.

First, let’s see what actually the Sqoop Eval is.

 

What is Sqoop Eval?

The Sqoop eval allows us to run SQL queries against the database. It prints the results on the console. Also, it allows us to preview our import queries to ensure that the data has been imported as expected.

In simpler words, the Sqoop Eval is available for modeling as well as for defining SQL statements. It allows users to run the user-defined SQL queries against the database and show the results on the console.

We can evaluate any type of SQL queries, either DDL or DML, by using Sqoop Eval.

Why Sqoop Eval?

The main purpose of the Sqoop Eval is to allow the users to execute SQL queries against the database quickly. The results are then shown on the console. Also, it allows the users to preview their Apache Sqoop import queries to ensure them that they have imported the data they expected.

Note: Basically, the Sqoop Eval is provided only for evaluation purposes. We generally use it for just verifying database connection from within the Apache Sqoop or for testing simple queries. We cannot use the Sqoop Eval in the production workflows.

Sqoop Eval Syntax:

$ sqoop eval (generic-args) (eval-args)
$ sqoop-eval (generic-args) (eval-args)

We can enter eval arguments in any order with respect to each other, but the Hadoop generic arguments must precede eval arguments.

Let us now see the Common arguments and the SQL Evaluation arguments.

Common Arguments

Argument Description
–connect <jdbc-uri> This argument specifies JDBC connect string
–connection-manager <class-name> This argument specifies connection manager class to use
–driver <class-name> This argument specifies the manually specified JDBC driver class to use
–hadoop-home <dir> This argument specifies the override $HADOOP_HOME
–help This argument specifies the print usage instructions
-P This argument read password from console
–password <password> This argument sets the authentication password
–username <username> This argument sets the  authentication username
–verbose This argument print more information while working
–connection-param-file <filename> This argument specifies optional properties file who provides connection parameters

SQL Eval Arguments

Argument Description
-e,–query <statement> This argument is used for specifying execute statements in SQL.

Let us now study Sqoop Eval with the help of an example.

Steps to be done before any SQL Query Evaluation

1: First change the directory to the /usr/local/hadoop/sbin by using the command

cd /usr/local/hadoop/sbin

2: Start all the Hadoop daemons by using the below command:

start-all.sh

3: Run the jps command.

jps

4: Now change the directory to the /usr/local/Sqoop/bin by using the below command:

cd /usr/local/sqoop/bin

SQL Select query Evaluation in Sqoop Eval

Suppose we have to select the five records from the emp_info table in the database demo. Then we can do so by running the below command:

sqoop eval --connect jdbc:mysql://localhost/demo \
    --query "SELECT * FROM emp_info LIMIT 5"

SQL Insert query Evaluation in Sqoop Eval

Suppose we have to insert a row in the table emp_info present in the database demo, which contains emp_name, emp_designation, and emp_state. Then we can do so by running the below command:

$ sqoop eval --connect jdbc:mysql://localhost/demo \
    -e "INSERT INTO emp_info VALUES('Raj', 'Junior Eng.', 'MP' )"

If the command executes successfully, then this command will display the status of updated rows on the console.
This is all about Sqoop Eval.

Summary

In short, we can say that Sqoop Eval is a tool that allows users to run their SQL queries against the database. The article had explained the whole concept of Sqoop Eval.

I hope you clearly understand the main purpose of Sqoop Eval and its syntax and commands after reading this article.

The article has enlisted the common arguments as well as the evaluation arguments. Moreover, you had also seen the Select Query Evaluation and the Insert Query Evaluation.

If you are still having any queries regarding Sqoop Eval, then share it with us in the comment section.