top of page
Writer's pictureJatin Madaan

Hive SQL return code check


While running hive query using hive -e or hive -f command merely writing rc=$? below hive command will not help , it will only tell if hive connected successfully or not .


If it is required to check whether there was any error during running of hive command then we need to first create a log file and then find error in file and return accordingly . Here catch is if we have keyword 'error' in column name or any other part of query then this will not work , for that case we need to exclude that column value first and then check .


Step 1 : Create rc function in unix


function rc_check {

rc_f=$1

script_name=$2

if (($rc_f == 0 )) ; then

echo "There is some issue in hive command please check $script_name!"

exit 1

else

echo "The job completed successfully enjoy !!"

fi


}


Step 2 : Run hive command and create log


DIR=`pwd`

hive -e "desc schema_name.table_name" > $DIR/log_name.log 2>&1



Step 3 : Find error and call function


cat $DIR/log_name.log |grep -i error

rc_check $? script_name




19 views1 comment

1 Comment


junehimanshi7
Mar 28, 2019

Awesome Jatin , It helped me in clearing my interview . You Rock !

Like
bottom of page