蜂巢如何选择除一列以外的所有列?

Roc*_*ief 7 hive hiveql

假设我的桌子看起来像这样:

Col1 Col2 Col3.....Col20 Col21
Run Code Online (Sandbox Code Playgroud)

现在我要选择除Col21以外的所有内容。在插入其他表之前,我想将其更改为unix_timestamp()。因此,简单的方法是执行以下操作:

INSERT INTO newtable partition(Col21) 
SELECT Col1, Col2, Col3.....Col20, unix_timestamp() AS Col21
FROM oldTable
Run Code Online (Sandbox Code Playgroud)

我有办法在蜂巢中实现这一目标吗?非常感谢你的帮助!

Shu*_*Shu 7

尝试设置以下属性

set hive.support.quoted.identifiers=none;
Run Code Online (Sandbox Code Playgroud)

然后选择除 col_21:

select `(col_21)?+.+` from <table_name>; 
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参考链接。

然后插入语句将

insert into <tablename> partition (col21) 
select `(col_21)?+.+` from ( --select all columns from subquery except col21
select *, unix_timestamp() AS alias_col21 from table_name --select *, create new col based on col21
)a;
Run Code Online (Sandbox Code Playgroud)

通过使用这种方法,您将拥有alias_col21作为select语句的最后一列,以便您可以基于该列进行分区。

如果加入:

我们不能引用每个表中的各个列((t1.id)?+.+..etc),因此将不必要的列放在select语句中。

hive>insert into <tablename> partition (col21)
select * from (
       select t1.* from
         (--drop col21 and create new alias_col21 by using col21
          select `(col21)?+.+`, unix_timestamp() AS alias_col21 from table1
         ) t1 
    join table2 t2 
  on t1.<col-name>=t2.<col-name>)a;
Run Code Online (Sandbox Code Playgroud)