在 Hive 中命名案例的结果



我对蜂巢很陌生。 使用我的 case 语句,我正在尝试创建一个名为 period 的变量,该变量在一个时间段内为零,在另一个时间段内为零,但我收到"无法识别输入"错误。 如何在配置单元中命名大小写表达式的结果? 它会将自己命名为_c7或类似的东西,但是我在下一步中使用此_c7变量时遇到问题(eof 错误(。

CREATE TABLE abc.temp2 AS 
SELECT a.*,
case 
when to_date(date)>='2016-07-01' and to_date(date)<'2017-07-01' then 0 
when to_date(date)>='2017-07-01' and to_date(date)<'2018-07-01' then 1
else null 
end **as period,**
array_contains(z,'abc') as abc,
array_contains(z,'def') as def
FROM abc.temp a;

只需将case语句放在一组括号中即可。

CREATE TABLE abc.temp2 AS 
SELECT a.*,
(case 
when to_date(date)>='2016-07-01' and to_date(date)<'2017-07-01' then 0 
when to_date(date)>='2017-07-01' and to_date(date)<'2018-07-01' then 1
else null 
end) as period,
array_contains(z,'abc') as abc,
array_contains(z,'def') as def
FROM abc.temp a;

最新更新