Support Questions
Find answers, ask questions, and share your expertise

How to store the value of a sqoop eval statement in a variable

New Contributor


I have a requirement where I need to compare the value that exists in a source table i.e. in Teradata vs the data that I am pulling into, the destination table, i.e. Hadoop.

I do know that there is a way to load the value into a textfile in HDFS, but am unable to store the value into a variable.

This is what I have done this far:

MYVAL=$(sqoop eval \ -libjars $LIB_JARS -Dteradata.db.input.job.type=hive \ --connect "jdbc:teradata://XXXXXXx" \ --username XXXXXX \ --password XXXXX \ --query "select count(*) from database_name.table_name | awk'/([0-9]+)/{print $2}');")

var=`env -i hive -S -e "select count(*)from database_name.table_name ;"`

echo $MYVAL

echo $var


@Benhail Muthyala

Sqoop eval with select query basically returns the output of the query on the terminal and storing the same onto a variable is not possible. You can do following:

sqoop eval \ -libjars $LIB_JARS -Dteradata.db.input.job.type=hive \ --connect "jdbc:teradata://XXXXXXx" \ --username XXXXXX \ --password XXXXX \ --query "select count(*) from database_name.table_name 1> sqoop.out 2>sqoop.err

hive -S -e "select count(*)from database_name.table_name ;" 1> hive.out 2>hive.err

The files sqoop.out and hive.out would include some log messages as well which could be grepped and removed.

; ;