select a.*, b.val
from a lateral view explode(array(1,2,3,4)) b as val;
How do I cross-join a table with a list?
Frage
If I have a table mytable
and a list
set vals = (1,2,3,4);
and I want to cross-join the table with the list (getting a new table which has 4 time as many rows as the original table and an extra val
column), do I have a better option than creating an explicit temp table?
What I can do is:
select a.*, b.val
from mytable a cross join
(select stack(4,1,2,3,4) as (val) from
(select * from mytable limit 1) z) b;
EDIT: My main use case would be passing -hiveconf vals='4,1,2,3,4'
to hive
and replacing stack(4,1,2,3,4)
with stack(${hiveconf:vals})
in the above code.
Lösung 2
Andere Tipps
I dont know this will help.
SELECT *
from mytable cross join
(select 1 as p
union
select 2
union
select 3
union
select 4) as x
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow