Hive:在子查询中添加分区列数据

问题描述 投票:0回答:1

我有2个hive表,它们具有完全相同的模式,除了日期列。其中一个有日期列,它是分区的,另一个没有日期列,没有任何分区。

这两个表是:

staging (no date column and not partitioned)  
main (date column present and is partitioned by date)

我想将数据从staging复制到main。我正在尝试这个查询

INSERT OVERWRITE TABLE main
        PARTITION (dt='2019-04-30')
                SELECT col_a,
                col_b,
                col_c,
                col_d,
                col_e,
                '2019-04-30' FROM staging

staging和main表都有col_a,col_b,col_c,col_d和col_e。 dt是只有主表所具有的字段。但是这会抛出这个错误:

main requires that the data to be inserted have the same number of columns as the target table: target table has 6 column(s) but the inserted data has 7 column(s), including 1 partition column(s) having constant value(s).;'

知道如何解决这个问题吗?

hive hiveql
1个回答
1
投票

好吧,事实证明我所要做的就是 -

INSERT OVERWRITE TABLE main
        PARTITION (dt='2019-04-30')

                SELECT * FROM staging
© www.soinside.com 2019 - 2024. All rights reserved.