配置单元插入从一个表覆盖到另一个具有不同列数的表

im9ewurl  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(476)

我有两张Hive桌。
源表有以下列:

correspondence_id       | decimal(22,0)  |          |
| template_id             | decimal(18,0)  |          |
| language_cd             | varchar(6)     |          |
| delivery_channel_cd     | varchar(20)    |          |
| job_id                  | decimal(18,0)  |          |
| correspondence_content  | string         |          |
| create_user_id          | varchar(40)    |          |
| create_ts               | timestamp      |          |
| last_updt_user_id       | varchar(40)    |          |
| last_updt_ts            | timestamp      |          |
| data_src_id             | decimal(18,0)  |          |
| src_app_resource_cd     | varchar(50)

目标包含以下列:

correspondence_id        | decimal(22,0)         |                       |
| template_id              | decimal(18,0)         |                       |
| template_cd              | varchar(20)           |                       |
| template_type_cd         | varchar(40)           |                       |
| category_cd              | varchar(20)           |                       |
| language_cd              | varchar(6)            |                       |
| delivery_channel_cd      | varchar(20)           |                       |
| job_id                   | decimal(18,0)         |                       |
| correspondence_content   | string                |                       |
| create_user_id           | varchar(40)           |                       |
| create_ts                | timestamp             |                       |
| last_updt_user_id        | varchar(40)           |                       |
| last_updt_ts             | timestamp             |                       |
| data_src_id              | decimal(18,0)         |                       |
| src_app_resource_cd      | varchar(50)           |                       |
| part_create_year_num     | int                   |                       |
| part_create_month_num    | int                   |                       |
|                          | NULL                  | NULL                  |
| # Partition Information  | NULL                  | NULL                  |
| # col_name               | data_type             | comment               |
|                          | NULL                  | NULL                  |
| part_create_year_num     | int                   |                       |
| part_create_month_num    | int

im使用以下查询传输数据:

FROM source_table cc insert overwrite table 
destination_table partition 
(part_create_year_num=2016, part_create_month_num=9 )
select cc.correspondence_id, cc.template_id, cc.language_cd, cc.delivery_channel_cd, cc.job_id, 
cc.correspondence_content, cc.create_user_id, cc.create_ts, cc.last_updt_user_id, cc.last_updt_ts, 
cc.data_src_id, cc.src_app_resource_cd

但是当我运行这个查询时,我得到以下错误

rror: Error while compiling statement: FAILED: SemanticException [Error 10044]: Line 1:79 Cannot insert into target table because column number/types are different '9': Table insclause-0 has 15 columns, but query has 12 columns. (state=42000,code=10044)
org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: SemanticException [Error 10044]: Line 1:79 Cannot insert into target table because column number/types are different '9': Table insclause-0 has 15 columns, but query has 12 columns.

很明显,源表和目标表是不同的,但是如何才能使这个查询工作,我尝试过输入占位符值,但也没有工作。

vsaztqbk

vsaztqbk1#

似乎目标表有五个额外的列
标准列:1模板| varchar(20)| 2模板|类型| varchar(40)| 3类别| cd | varchar(20)||
分区列4。创建第5年。零件|创建|月份|整数
查询应为

Insert overwrite table Destination_table partition(part_create_year_num=2016, part_create_month_num=9 )  select
 correspondence_id,        
 template_id,      
 '' as template_cd,      
'' as  template_type_cd, 
 '' as category_cd,      
 language_cd,      
 delivery_channel_cd,
 job_id,
 correspondence_content,
 create_user_id,
 create_ts,
 last_updt_user_id,
 last_updt_ts,
 data_src_id,
 src_app_resource_cd
 from source_table

相关问题