【发布时间】:2018-09-27 11:11:21
【问题描述】:
当我运行以下 hive 命令时
hive -e 'select msg, count(*) as cnt from table where msg like “%abcd%” 按 msg 顺序按 cnt desc 分组;' | sed 's/[\t]/,/g' > 表格.csv
我收到以下错误。
失败:ParseException line 1:89 无法识别“like”附近的输入 '%' 'password' 在表达式规范中
我知道指定字符串“%abcd%”时存在问题。该命令在 hive 环境中运行良好,但在这里我试图将结果保存到 csv 文件。我该如何纠正这个错误?
【问题讨论】:
-
问题是 Hive 使用单引号作为字符串,所以你需要写
like '%abcd%'并使用双引号作为 bash 字符串 -
@serge_k 也试过了
hive -e 'select msg, count(*) as cnt from table where msg like '%password%' group by msg order by cnt desc ;' | sed 's/[\t]/,/g' > table.csv。但得到同样的错误。 -
然而,这很好
hive -e "select msg, count(*) as cnt from table where msg like '%password%' group by msg order by cnt desc ;" | sed "s/[\t]/,/g" > table.csv -
其实这就是我写“使用双引号作为 bash 字符串”时的意思。
标签: hive