web-dev-qa-db-ja.com

Hive 1列以外のすべてを選択する方法

私のテーブルが次のように見えると仮定します:

Col1 Col2 Col3.....Col20 Col21

ここで、Col21を除くすべてを選択します。他のテーブルに挿入する前に、unix_timestamp()に変更したい。したがって、簡単なアプローチは次のようなことをすることです。

INSERT INTO newtable partition(Col21) 
SELECT Col1, Col2, Col3.....Col20, unix_timestamp() AS Col21
FROM oldTable

ハイブでこれを達成する方法はありますか?ご協力ありがとうございました!

7
Rocking chief

以下のプロパティを設定してみてください

set Hive.support.quoted.identifiers=none;

次に、col_21:を除くすべての列を選択します

select `(col_21)?+.+` from <table_name>; 

詳細については、 this リンクを参照してください。

次に、挿入ステートメントは

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;

このアプローチを使用することにより、selectステートメントの最後の列としてalias_col21を使用して、その列に基づいてパーティションを作成できます。

結合の場合:

各テーブルから個々の列((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;
7
Shu