ARRAY_CONTAINS配置单元中的多个值 [英] ARRAY_CONTAINS muliple values in hive

查看:3391
本文介绍了ARRAY_CONTAINS配置单元中的多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方便的方法在配置单元中使用ARRAY_CONTAINS函数来搜索数组列中的多个条目而不仅仅是一个?因此而不是:

  WHERE ARRAY_CONTAINS(array,val1)OR ARRAY_CONTAINS(array,val2)

我想写:

  WHERE ARRAY_CONTAINS(array,val1,val2)

完整的问题是我需要阅读 val1 val2 在命令行参数中动态运行脚本时,我通常不知道有多少值以...为条件。所以你可以想象 vals 是一个逗号分隔的列表(或数组),它包含值 val1 val2 ... ,并且我想写

  WHERE ARRAY_CONTAINS(array,vals)

预先感谢!

解决方案

有一个UDF 这里,它可以让你取两个数组的交集。假设你的值有结构

  values_array = [val1,val2,...,valn] 

然后您可以做

pre $ 其中array_intersection(array,values_array)[0]不为空

如果它们没有任何元素通常会返回 [] ,因此 [] [0] 将会是 null


Is there a convenient way to use the ARRAY_CONTAINS function in hive to search for multiple entries in an array column rather than just one? So rather than:

WHERE ARRAY_CONTAINS(array, val1) OR ARRAY_CONTAINS(array, val2)

I would like to write:

WHERE ARRAY_CONTAINS(array, val1, val2)

The full problem is that I need to read val1 and val2 dynamically from the command line arguments when I run the script and I generally don't know how many values will be conditioned on. So you can think of vals being a comma separated list (or array) containing values val1, val2, ..., and I want to write

WHERE ARRAY_CONTAINS(array, vals)

Thanks in advance!

解决方案

There is a UDF here that will let you take the intersection of two arrays. Assuming your values have the structure

values_array = [val1, val2, ..., valn]

You could then do

where array_intersection(array, values_array)[0] is not null

If they don't have any elements in common, [] will be returned and therefore [][0] will be null

这篇关于ARRAY_CONTAINS配置单元中的多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆