0

次のように、2つの外部ハイブテーブルがあります。sqoop を使用して Oracle からデータを入力しました。

create external table transaction_usa
(
tran_id int,
acct_id int,
tran_date string,
amount double,
description string,
branch_code string,
tran_state string,
tran_city string,
speendby string,
tran_zip int
)
row format delimited
stored as textfile
location '/user/stg/bank_stg/tran_usa';

create external table transaction_canada
(
tran_id int,
acct_id int,
tran_date string,
amount double,
description string,
branch_code string,
tran_state string,
tran_city string,
speendby string,
tran_zip int
)
row format delimited
stored as textfile
location '/user/stg/bank_stg/tran_canada';

上記の 2 つのテーブルのデータを、上記の 2 つのテーブルとすべて同じフィールドを持つ 1 つの外部ハイブ テーブルにそのままマージしますが、どのデータがどのテーブルからのものかを識別するために 1 つの余分な列があります。として追加の列を持つ新しい外部テーブルsource_table。新しい外部テーブルは次のとおりです。

create external table transaction_usa_canada
(
tran_id int,
acct_id int,
tran_date string,
amount double,
description string,
branch_code string,
tran_state string,
tran_city string,
speendby string,
tran_zip int,
source_table string
)
row format delimited
stored as textfile
location '/user/gds/bank_ds/tran_usa_canada';

どうすればできますか?

4

3 に答える 3

1

SELECT各テーブルから実行しUNION ALL、これらの結果に対して操作を実行し、最後に結果を 3 番目のテーブルに挿入します。

以下は、最終的なハイブ クエリです。

INSERT INTO TABLE transaction_usa_canada
SELECT tran_id, acct_id, tran_date, amount, description, branch_code, tran_state, tran_city, speendby, tran_zip, 'transaction_usa' AS source_table FROM transaction_usa
UNION ALL
SELECT tran_id, acct_id, tran_date, amount, description, branch_code, tran_state, tran_city, speendby, tran_zip, 'transaction_canada' AS source_table FROM transaction_canada;

これがあなたを助けることを願っています!!!

于 2016-05-18T12:50:25.090 に答える