2016-05-05 49 views
1

我想根據現有表中的列創建新表,在配置單元中添加新的分區列。在Hive SQL中,使用分區鍵創建基於另一個表的列的表

而且我想實現hive sql中的目標。

是否有任何其他方式比以下sql或使用ETL工具如水壺。

create table if not exists table_name(
col1,
col2,
col3,
……,
coln
)partitioned by dt;

其中col1到coln來自已經存在的舊錶,dt是新添加的分區鍵。

由於舊錶太大,可能有數百列,列出它們會很累。

但是,下面的SQL顯示語法錯誤:

create table if not exists table_name like older_table_name partitioned by dt;

所以我想知道有沒有其他更好的辦法在蜂巢SQL來解決這個問題?謝謝。

回答

1

如果所有列和DT columnYou可以使用下面的方法來創建分區表:

CREATE TABLE newtable (col1 int, col2 string) PARTITIONED BY (dt string) AS 
SELECT col1 , col2, dt FROM oldtable WHERE dt is not null; 
相關問題