需要定时导出hive表,有如下脚本:
#!/bin/bash
HQL="select * from test where concat(year, month, day) = '20200321'"
hive -e $HQL > result.txt
执行时提示如下错误:
FAILED: ParseException line 1:6 cannot recognize input near '<EOF>' '<EOF>' '<EOF>' in select clause
你看得满头雾水,多半以为是编码错误,但无论你怎么调整,错误依旧。
其实问题在“hive -e $HQL”这句,正确的写法是:
#!/bin/bash
HQL="select * from test where concat(year, month, day) = '20200321'"
# 务必用双引号包着SQL语句,如下
hive -e "$HQL" > result.txt