Error: Error while compiling statement: FAILED: SemanticException Unable to load data to destination

博客讲述了在Hive中遇到的数据加载错误,问题源于新建表的存储格式与源数据格式不匹配。通过查看建表语句发现新表使用了ORC存储格式,而源数据是按制表符分隔的文本文件。为了解决这个问题,重新创建表时指定了STORED AS TEXTFILE的存储格式,使得加载成功。

ods层新加了一张表,和以前的格式一样

DROP TABLE IF EXISTS ods_students_industry_level;
CREATE TABLE `ods_students_industry_level` (
  `id` INT COMMENT '编号',
  `first_industry` STRING COMMENT '一级行业',
  `second_industry` STRING COMMENT '二级行业',
  `parent_id` INT COMMENT '父级id'
) COMMENT '行业级别信息表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
LOCATION '/hive/warehouse/ods/ods_students_industry_level';

数据从hdfs load到表的时候报错

load语句:

load data inpath '/origin_data/sqoop/db/students_firstindustry/2022-04-12' OVERWRITE into table sqoop. partition(dt='2022-04-12');"

load失败报错:

Error: Error while compiling statement: FAILED: SemanticException Unable to load data to destination table. Error: The file that you are trying to load does not match the file format of the destination table

文件格式不对。

查看建表的格式:

hive> show create table ods_students_industry_level;

+----------------------------------------------------+
|                   createtab_stmt                   |
+----------------------------------------------------+
| CREATE TABLE `ods_students_industry_level`(        |
|   `id` int COMMENT '??',                           |
|   `first_industry` string COMMENT '????',          |
|   `second_industry` string COMMENT '????',         |
|   `parent_id` int COMMENT '??id')                  |
| COMMENT '???????'                                  |
| PARTITIONED BY (                                   |
|   `dt` string)                                     |
| ROW FORMAT SERDE                                   |
|   'org.apache.hadoop.hive.ql.io.orc.OrcSerde'      |
| WITH SERDEPROPERTIES (                             |
|   'field.delim'='\t',                              |
|   'serialization.format'='\t')                     |
| STORED AS INPUTFORMAT                              |
|   'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'  |
| OUTPUTFORMAT                                       |
|   'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat' |
| LOCATION                                           |
|   'hdfs://hdp-01:8020/hive/warehouse/ods/ods_students_industry_level' |
| TBLPROPERTIES (                                    |
|   'bucketing_version'='2',                         |
|   'transactional'='true',                          |
|   'transactional_properties'='default',            |
|   'transient_lastDdlTime'='1649831799')            |
+----------------------------------------------------+

查看以前的建的表的格式

+----------------------------------------------------+
|                   createtab_stmt                   |
+----------------------------------------------------+
| CREATE EXTERNAL TABLE `ods_dh_userlevels`(         |
|   `id` int COMMENT '??',                           |
|   `name` string COMMENT '???',                     |
|   `weight` int,                                    |
|   `visirble` int,                                  |
|   `price` int COMMENT '??',                        |
|   `create_time` string COMMENT '????',             |
|   `describe` string COMMENT '????',                |
|   `priceclassify` int,                             |
|   `remarks` string)                                |
| COMMENT 'datahoop???????'                          |
| PARTITIONED BY (                                   |
|   `dt` string)                                     |
| ROW FORMAT SERDE                                   |
|   'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'  |
| WITH SERDEPROPERTIES (                             |
|   'field.delim'='\t',                              |
|   'serialization.format'='\t')                     |
| STORED AS INPUTFORMAT                              |
|   'org.apache.hadoop.mapred.TextInputFormat'       |
| OUTPUTFORMAT                                       |
|   'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' |
| LOCATION                                           |
|   'hdfs://hdp-01:8020/text/hive/ods/ods_dh_userlevels' |
| TBLPROPERTIES (                                    |
|   'bucketing_version'='2',                         |
|   'discover.partitions'='true',                    |
|   'transient_lastDdlTime'='1648629277')            |
+----------------------------------------------------+

 

可以看出来两张表的存储格式改变了。

hive默认的存储格式是textFile。

对新的表指定存储格式,即在建表的时候加一句 store as textFile

新的建表语句:

DROP TABLE IF EXISTS ods_students_industry_level;
CREATE TABLE `ods_students_industry_level` (
  `id` INT COMMENT '编号',
  `first_industry` STRING COMMENT '一级行业',
  `second_industry` STRING COMMENT '二级行业',
  `parent_id` INT COMMENT '父级id'
) COMMENT '行业级别信息表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE
LOCATION '/hive/warehouse/ods/ods_students_industry_level';

这次load成功。

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值