Kane
Kane

Reputation: 3

How can i use the mysql query result in hive query

I have a requirement like using mysql query result into hive query in shell script for this I have implemented below code

ctrl_tbl_date=`mysql -N -h ${Mysql_Host_Name} -u ${Mysql_Uname} -p${Mysql_pwd} -e "use ${MySQLDB};select max(Processing_Datetime) from ${Ctrl_Tbl}:"`

echo "$ctrl_tbl_date">>/edh_fw/scripts/sqoop_export_by_key/out_test6.txt 

echo "taking the data which is satisfying below conditions"

temp=hive -v -e "set hive.exec.compress.output=false;insert overwrite directory '${temp_incremental_loc}' row format delimited fields terminated by '\t' stored as textfile select * from ${src_table} where createDate>'${ctrl_tbl_date}';"

echo "$temp">>/edh_fw/scripts/sqoop_export_by_key/out_test7.txt 

I'm passing every value as a dynamic from execution line I have initialized on top of the script .. Here I'm not getting the ctrl_tbl_date into hive query of course MYSQL result is not assigning to the variable...Kindly help me on this

Upvotes: 0

Views: 134

Answers (1)

kartik
kartik

Reputation: 168

Use

 temp=$(hive -v -e "set hive.exec.compress.output=false;insert overwrite directory '${temp_incremental_loc}' row format delimited fields terminated by '\t' stored as textfile select * from ${src_table} where createDate>'${ctrl_tbl_date}';")

so as to put the result of inside query inside temp variable...

Right now , without using the $(), as below

temp=hive -v -e "set hive.exec.compress.output=false;insert overwrite directory '${temp_incremental_loc}' row format delimited fields terminated by '\t' stored as textfile select * from ${src_table} where createDate>'${ctrl_tbl_date}';"

u r just assigning whatever is wriiten on right side to left side but u actually want to assign the result of execution of right side to the left side...

Upvotes: 0

Related Questions