How do I create a hive table without any intermediate files?

前端 未结 2 1860
囚心锁ツ
囚心锁ツ 2021-01-15 23:06

I want to create and populate a hive table without loading anything from disk.

Specifically, I have

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


        
相关标签:
2条回答
  • 2021-01-15 23:42

    As explained in 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;
    

    Alas, strictly speaking, this requires <an_already_existing_non_empty_table>...

    0 讨论(0)
  • 2021-01-15 23:50
    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 讨论(0)
提交回复
热议问题