简体   繁体   English

我如何在Hive查询中使用mysql查询结果

[英]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 我有一个要求,例如在外壳脚本中使用mysql查询结果到配置单元查询中,为此我已经在以下代码中实现了

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 我在脚本顶部初始化的执行行中将每个值作为动态值传递..在这里,我没有将ctrl_tbl_date到配置单元查询中,当然,MYSQL结果没有分配给该变量...请帮助我这个

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... 以便将内部查询的结果放在temp变量中...

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}';"

ur 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... 我们只是将右侧的内容分配给左侧,但是您实际上想将右侧的执行结果分配给左侧...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM