I have a Hive table and I need to run a query similar to the one below for different values of the parameters date
,identifier1
,identifier2
,lower
and upper
and union the results together.
Select
col1,
col2,
new_time,
sum(col3),
case
when "date" between date1 and date2 then 'No'
when "date" between date3 and date4 then 'Yes'
end as date_group,
case when "date" < e then 'test1' else 'test2' end as test_group,
'identifier1' as ID,
'identifier2' as ID2
FROM Table1
WHERE (new_time between time1 and time2)
AND (tag between 'lower' and 'upper')
GROUP BY
col1,
col2,
new_time,
case
when "date" between date1 and date2 then 'No'
when "date" between date3 and date4 then 'Yes'
end,
case when "date" < e then 'test' else 'test2' end
My initial idea was to create the parameter table below and loop through each row which holds combination of parameter values and union the results.
+------------+-------------+-------------+--------+-------+
| date | identifier1 | identifier2 | lower | upper |
+------------+-------------+-------------+--------+-------+
| 2019-05-12 | 1 | A | 10 | 20 |
| 2019-07-10 | 2 | B | 30 | 40 |
| 2019-04-10 | 3 | C | 60 | 70 |
| 2019-04-11 | 4 | D | 423 | 500 |
| 2019-07-10 | 5 | E | 85 | 88 |
+------------+-------------+-------------+--------+-------+
Two problems, I'm not sure how to go about this and I'm not sure if hiveql allows loops. I would prefer a hive solution but a SQL solution could work if I'm able to move my intermediate table to a relational database. A solution would be equivalent to the union query below which has the parameter values highlighted.
Any help with a solution is appreciated, thanks.