Write a shell script from HDFS derivative to Hive, given as follows:
mismatched input '<EOF>' expecting DATA near 'load' in load statement
shell code is as follows:
#!/bin/bash do_date=$1 APP=gmall hive=/opt/module/hive/bin/hive sql=" load data inpath '/origin_data/$APP/db/user_info/$do_date' OVERWRITE into table $APP.ods_user_info partition(dt='$do_date'); " $hive -e $sql
The cause of the error is the last $ sql need to add double quotes "", otherwise $ sql later can not be parsed into the value of ( / origin_data / GMALL / db / user_info / 2019-12-08 OVERWRITE INTO the Table gmall.ods_user_info Partition (dt = '2019-12-08') ) recognized as string
Changed to $ Hive -e " $ SQL."
Note the difference between single and double quotes in the shell: !!!
Single quotes: output the contents of quotes is output.
Double quotes: will first variable, command, parse out the results of the escape character, even if there are variables in double quotes single quotation marks, it will be parsed into the value of the variable, and then output the final content.
E.g:
#!/bin/bash do_date=$1 APP=gmall hive=/opt/module/hive/bin/hive
sql="load data inpath '/origin_data/$APP/db/user_info/$do_date' OVERWRITE into table $APP.ods_user_info partition(dt='$do_date');"
echo '/origin_data/$APP/db/user_info/$do_date' echo "$sql"
root@hadoop102 bin]# ods_order_info.sh 2019-12-08
Output:
/origin_data/$APP/db/user_info/$do_date load data inpath '/origin_data/gmall/db/user_info/2019-12-08' OVERWRITE into table gmall.ods_user_info partition(dt='2019-12-08');