一般我们使用 hive sql 中的case when是以下两种形式
CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END
CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END
在将xgb模型转化为sql的过程中,用嵌套判断模式,会减少计算量,因此搜索了一下如何在hive中实现嵌套格式的if-else判断,以下是测试语句,证明嵌套是支持的。
select
case when (7 < 22.1) then
case when (7 < 12.5214) then
case when (7 < 6.1) then
case when (7 >= 33.05) then
-0.000374448
else
0.0283531
end
else
case when (7 < 4.6625) then
0.0502409
else
-0.0232666
end
end
else
case when (7 >= 0.0714286) then
case when (7 < 83.75) then
0.0427497
else
-0.0530864
end
else
case when (7 >= 878.333) then
-0.176592
else
0.0242326
end
end
end
else
case when (7 < 25.7) then
case when (7 >= 1.5) then
case when (7 < 1.5) then
-0.0454422
else
-0.162755
end
else
0.109085
end
else
case when (7 < 138.425) then
case when (7 < 7.25) then
-0.0194004
else
0.116519
end
else
case when (7 >= 0.878676) then
0.156834
else
0.0183544
end
end
end
end
as tree_481_score;
来源:CSDN
作者:wgdzz
链接:https://blog.csdn.net/wgdzz/article/details/88012983