我发现一个月的天数如下。
set ndays=datediff(CONCAT(y, '-', (m + 1), '-', '01'), CONCAT(y, '-', m, '-', '01')) FROM (SELECT month(current_date) as m, year(current_date) as y, day(current_date)) tabl1;
我正在检查数值。
select ${hiveconf:ndays}; --O/P 31
我在一个查询中使用这个变量,得到一个错误。
select
sum(price)/ ${hiveconf:ndays}
from sales_aly
GROUP BY sales_month;
失败:parseexception行3:0在“tabl1”附近的“from”处缺少eof
请帮帮我。
提前谢谢。
1条答案
按热度按时间kcwpcxri1#
set
命令将不计算此表达式的值:datediff(CONCAT(y, '-', (m + 1), '-', '01'), CONCAT(y, '-', m, '-', '01')) FROM (SELECT month(current_date) as m, year(current_date) as y, day(current_date)) tabl1
但将表达式本身指定为值。然后,当您在代码中使用变量时,将替换表达式而不是变量。您可以在shell中计算表达式并将其传递给配置单元,如下所示:
脚本中的地址变量:
${hiveconf:ndays}
也可以使用宏。看这个:http://svn.apache.org/repos/asf/hive/trunk/ql/src/test/queries/clientpositive/macro.q