【问题标题】:Merge 2 external hive tables into single new table将 2 个外部配置单元表合并到一个新表中
【发布时间】:2016-09-14 18:24:51
【问题描述】:

我是蜂巢新手。我创建了 2 个外部配置单元表,并使用 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';

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

请帮忙。

【问题讨论】:

标签: hive external-tables


【解决方案1】:

如果您的 2 个外部表具有相同的列结构,则可以将文本文件复制到一个公共位置或文件夹并创建一个指向新位置的新表。

如果2个外部表的元数据不同,可以考虑“create table as select”选项加载到新表。

【讨论】:

【解决方案2】:

您可以使用联合语句将它们读入新表。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-16
    • 2021-10-09
    • 2021-07-05
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多