《 Hive编程》一书列出了Hive中内置的test in
函数,但是如何使用它并不明显,我一直无法找到示例
这是来自Programming Hive的信息:
Return type Signature Description
----------- --------- -----------
BOOLEAN test in(val1, val2, …) Return true if testequals one of the values in the list.
我想知道它是否可以用来表示一个值是否在Hive数组中。
例如,如果我执行查询:
hive > select id, mcn from patients limit 2;
id mcn
68900015 ["7382771"]
68900016 ["8847332","60015163","63605102","63251683"]
我希望能够测试对于给定患者的mcn列表中是否包含这些数字之一,例如“60015163”。
不知道该怎么做。
我尝试了多种变体,但都无法解析。这是两个不起作用的示例:
select id, test in (mcn, "60015163") from patients where id = '68900016';
select id, mcn from patients where id = '68900016' and test mcn in('60015163');
最佳答案
该函数不是test in
bu而是in
。在表6-5中,test
是列名。
因此,为了知道某个值是否在Hive数组中,您需要首先在数组上使用explode
。
您可以创建一个UDF,而不是分解array列,如这里http://souravgulati.webs.com/apps/forums/topics/show/8863080-hive-accessing-hive-array-custom-udf-所述
关于hadoop - 如何使用内置的Hive “test in(val1, val2)”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19006401/