最近我开发了一个Hive Generic UDF getad 。它接受地图类型和字符串类型参数并输出字符串值。但我发现UDF输出在不同条件下确实令人困惑。
条件A:
select
getad(map_col, 'tp') as tp,
getad(map_col, 'p') as p,
getad(map_col, 'sp') as sp
from
table_name
where
id = xxxx;
输出正确:'tp','p','sp'。
条件B:
select
array(tp, p, sp) as ps
from
(
select
getad(map_col, 'tp') as tp,
getad(map_col, 'p') as p,
getad(map_col, 'sp') as sp
from
table_name
where
id = xxxx
) t;
输出错误:'tp','tp','tp'。
你能不能给我一些提示?谢谢!
答案 0 :(得分:0)
设置hive.cache.expr.evaluation = false后,所有查询都会输出预期结果。
我发现它与UDF中的getDisplayString函数有关。首先,该函数返回一个字符串,无论其参数如何。我必须设置hive.cache.expr.evaluation = false。
但在我将函数更改为依赖于参数返回字符串后,即使hive.cache.expr.evaluation设置为true,所有查询都会返回预期结果。