hive insert table的寫法

hive官方文檔中這樣描述將數據從一個表中插入到另一個表中

hive> FROM invites a INSERT OVERWRITE TABLE events SELECT a.bar, count(*) WHERE a.foo > 0 GROUP BY a.bar;
hive> INSERT OVERWRITE TABLE events SELECT a.bar, count(*) FROM invites a WHERE a.foo > 0 GROUP BY a.bar; 

The keyword 'overwrite' signifies that existing data in the table is deleted.
If the 'overwrite' keyword is omitted, data files are appended to existing data sets.

但若省略overwrite,則會報如下錯:

hive> INSERT TABLE events SELECT a.bar, count(*) FROM invites a WHERE a.foo > 0 GROUP BY a.bar;  
FAILED: ParseException line 1:0 cannot recognize input near 'insert' 'table' 'events' in insert clause
 

省略overwirite的正確寫法是:

hive> INSERT INTO TABLE events SELECT a.bar, count(*) FROM invites a WHERE a.foo > 0 GROUP BY a.bar;  


就這麼簡單,官方文檔中有這樣的寫法,可能不會引起大家的注意:

hive> LOAD DATA LOCAL INPATH './examples/files/kv2.txt' OVERWRITE INTO TABLE invites PARTITION (ds='2008-08-15'); 
hive> LOAD DATA LOCAL INPATH './examples/files/kv3.txt' OVERWRITE INTO TABLE invites PARTITION (ds='2008-08-08'); 

這是帶了into的,但將insert將在行首,沒有加into的寫法,所以一開始我也很迷糊。

官方文檔地址:https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-InstallationandConfiguration




 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章