将两个外部配置单元表合并到一个新表中

tf7tbtn2  于 2021-06-29  发布在  Hive
关注(0)|答案(2)|浏览(341)

我是新来的Hive。我创建了两个外部配置单元表,还使用sqoop从oracle导入了数据。另外,我还创建了一个新的外部表,其中包含这两个表的数据 External table 1 and External table 2 如下

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';

现在,我不知道如何将两个外部表的数据合并到上面的外部表中。
请帮忙。

swvgeqrz

swvgeqrz1#

可以使用union语句将它们读入新表。

INSERT OVERWRITE TABLE [database].[table]
SELECT 

* 

FROM (
SELECT 
Col_1 STRING,
Col_2 STRING,
Col_3 STRING
FROM
[table]
UNION ALL
SELECT
Col_1 STRING,
Col_2 STRING,
Col_3 STRING
FROM 
[table]) [table];
kpbpu008

kpbpu0082#

如果2外部表具有相同的列结构,则可以将文本文件复制到公共位置或文件夹,并创建指向新位置的新表。
如果2个外部表的元数据不同,可以考虑选择“create table as select”加载到新表。

相关问题