我有一个数据集,该数据集的一列包含一组时间戳记,而一列仅包含一个时间戳记。我正在寻找使用c1时间戳作为更大和更小的条件的数组的大小。
表格(my_table):
c1 | c2 |
----------------------------|
4 | [1,2,3,4,5,6,7,8,9,10] |
1 | [1,2,3,4,5,6,7,8,9,10] |
5 | [1,2,3,4,5,6,7,8,9,10] |
3 | [1,2,3,4,5,6,7,8,9,10] |
查询:
select
c1,
c2,
size(some_udf_split_on_c1(sort_array(<array>), c1)[1]) AS smaller_than_c1
size(some_udf_split_on_c1(sort_array(<array>), c1)[2]) AS larger_than_c1
from my_table
udf是我假设的实现。
输出:
c1 | c2 | smaller_than_c1 | larger_than_c1
----------------------------|-----------------|---------------
4 | [1,2,3,4,5,6,7,8,9,10] | 3 | 6
1 | [1,2,3,4,5,6,7,8,9,10] | 0 | 9
5 | [1,2,3,4,5,6,7,8,9,10] | 4 | 5
3 | [1,2,3,4,5,6,7,8,9,10] | 1 | 8
最佳答案
UDF将是您要寻找的最快的路径。可以结合使用explode和group bys来执行此操作,但是与10行UDF代码相比,仅编写UDF会更快乐。
关于java - hive 中带有条件参数的数组的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31502795/