I have a dataset that has a column with an array of timestamps and a column with just one timestamp. I'm looking to get the size of the array using the c1 timestamp as a condition for larger and smaller.
Table (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] |
Query:
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
The udf's there are my hypothesized implementation.
Output:
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