Hive总结(二) Hive导入时,格式不对错误

本文介绍了在使用Hive进行数据加载过程中常见的两种错误:文件格式与表定义不符及文本编码不一致,并提供了相应的解决思路。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本地load data到Hive表中,可能会由于一些表格式的问题或文本格式问题,导致上传失败。


总结原因:

1. 上传格式和建表格式不匹配

自己上传的为txt文本,而创建表指定的file format 是sequencefile。

[java]  view plain  copy
  1. hive> load data local inpath '/home/hadoop/ma_test.txt' into table sep26_ma_deposit_dim;  
  2. Copying data from file:/home/hadoop/ma_test.txt  
  3. Copying file: file:/home/hadoop/ma_test.txt  
  4. Loading data to table dw.sep26_ma_deposit_dim  
  5. Failed with exception Wrong file format. Please check the file's format.  
  6. FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask  

思路:

先导入存为textfile,然后再执行MR,覆写这个表

[java]  view plain  copy
  1. hive> create table tempshengli_test (t1 int, t2 int, t3 int, t4 string) row format delimited fields terminated by '\t' stored as textfile;  
  2. OK  
  3. Time taken: 0.256 seconds  
  4. hive> desc tempshengli_test;  
  5. OK  
  6. t1      int  
  7. t2      int  
  8. t3      int  
  9. t4      string  
  10. Time taken: 0.141 seconds  
  11. hive> load data local inpath '/home/hadoop/ma_test.txt' into table tempshengli_test;                                                        
  12. Copying data from file:/home/hadoop/ma_test.txt  
  13. Copying file: file:/home/hadoop/ma_test.txt  
  14. Loading data to table dw.tempshengli_test  
  15. OK  
  16. Time taken: 4.228 seconds  
  17.   
  18. hive> insert overwrite table sep26_ma_deposit_dim select * from tempshengli_test;     
  19. Total MapReduce jobs = 2  
  20. Ended Job = job_201403301416_112745  
  21. 16 Rows loaded to sep26_ma_deposit_dim  
  22. OK  
  23. Time taken: 64.341 seconds  
[java]  view plain  copy
  1. drop table tempshengli_test  

2.文本格式不匹配

还要注意格式, Unix UTF-8和Windows上的ANSI上传上去不一样。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值