2014-01-28 98 views
1

我想要创建并填充配置单元表,而不需要从磁盘加载任何东西。如何创建没有任何中间文件的配置单元表?

具体来说,我有

set idlist = (1,2,3); 
set values = (2,3,5); 

我想创建一个表9行:再次

id value 
1 2 
1 3 
1 5 
2 2 
2 3 
2 5 
3 2 
3 3 
3 5 

,我做想写csv文件,并将其加载到蜂巢。

使用案例:

  1. 迭代
  2. 那么问题产生小的测试样品

回答

3
create table my_table(id int, value int); 

insert overwrite table my_table 
select a.id as id, b.value as value from (
    select count(*) from my_table 
) t 
lateral view explode(array(1,2,3)) a as id 
lateral view explode(array(2,3,5)) b as value; 
0

Hive insert query like SQL解释说:

drop table if exists tmp__one; 
create table tmp__one as select 1 as one 
from <an_already_existing_non_empty_table> limit 1; 

drop table if exists tmp__ids; 
create table tmp__ids as select stack(3,1,2,3) as id 
from tmp__one; 

drop table if exists tmp__vals; 
create table tmp__vals as select stack(3,2,3,5) as val 
from tmp__one; 

drop table if exists my_table; 
create table my_table as select id, val 
from tmp__ids cross join tmp__vals; 

select * from my_table; 

drop table tmp__one; 
drop table tmp__ids; 
drop table tmp__vals; 

唉,严格地说,这需要<an_already_existing_non_empty_table> ...

相关问题