hive:MoveTask

运行SQL时出了个错:

SQL: INSERT OVERWRITE DIRECTORY 'result/testConsole' select count(1) from nutable; 

错误信息:

Failed with exception Unable to rename: hdfs://indigo:8020/tmp/hive-root/hive_2013-08-22_17-35-05_006_3570546713731431770/-ext-10000 to: result/testConsole
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask
另一个SQL的错误,这是日志中的:
1042 2013-08-22 17:08:54,411 INFO  exec.Task (SessionState.java:printInfo(412)) - Moving data to: result/userName831810250/54cbcd2980a64fe78cf54abb3116d2dc from hdfs://indigo:8020/tmp/hive-hive/hive_2013-08-22_17-08-40_062_3976325306495167351/-ext-10000
1043 2013-08-22 17:08:54,414 ERROR exec.Task (SessionState.java:printError(421)) - Failed with exception Unable to rename: hdfs://indigo:8020/tmp/hive-hive/hive_2013-08-22_17-08-40_062_3976325306495167351/-ext-10000 to: result/userName831810250/54cbcd2980a64fe78cf54abb3116d2dc

下面看看出现异常的地方。
执行SQL时,最后一个任务是MoveTask,它的作用是将运行SQL生成的Mapeduce任务结果文件放到SQL中指定的存储查询结果的路径中,具体方法就是重命名
下面是 org.apache.hadoop.hive.ql.exec.MoveTask 中对结果文件重命名的一段代码:

[java]  view plain copy print ?
  1. //这个sourcePath参数就是存放Mapeduce结果文件的目录,所以它的值可能是  
  2. //hdfs://indigo:8020/tmp/hive-root/hive_2013-08-22_18-42-03_218_2856924886757165243/-ext-10000  
  3. if (fs.exists(sourcePath)) {  
  4.     Path deletePath = null;  
  5.     // If it multiple level of folder are there fs.rename is failing so first  
  6.     // create the targetpath.getParent() if it not exist  
  7.     if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_INSERT_INTO_MULTILEVEL_DIRS)) {  
  8.     deletePath = createTargetPath(targetPath, fs);  
  9.     }  
  10.     //这里targetPath的值就是指定的放置结果文件的目录,值可能是 result/userName154122639/4e574b5d9f894a70b074ccd3981ca0f1  
  11.     if (!fs.rename(sourcePath, targetPath)) {//上面产生的异常就是因为这里rename失败,进了if,throw了个异常  
  12.       try {  
  13.         if (deletePath != null) {  
  14.           fs.delete(deletePath, true);  
  15.         }  
  16.       } catch (IOException e) {  
  17.         LOG.info("Unable to delete the path created for facilitating rename"  
  18.             + deletePath);  
  19.       }  
  20.       throw new HiveException("Unable to rename: " + sourcePath  
  21.           + " to: " + targetPath);  
  22.     }  
  23.   }  
rename的targetPath必须存在。
其实之前已经检查和创建targetPath了:

[java]  view plain copy print ?
  1. private Path createTargetPath(Path targetPath, FileSystem fs) throws IOException {  
  2.     Path deletePath = null;  
  3.     Path mkDirPath = targetPath.getParent();  
  4.     if (mkDirPath != null & !fs.exists(mkDirPath)) {  
  5.       Path actualPath = mkDirPath;  
  6.       while (actualPath != null && !fs.exists(actualPath)) {  
  7.         deletePath = actualPath;  
  8.         actualPath = actualPath.getParent();  
  9.       }  
  10.       fs.mkdirs(mkDirPath);  
  11.     }  
  12.     return deletePath;//返回新创建的最顶层的目录,万一失败用来删除用  
  13.   }  

Apache出现过这个 问题 ,已经解决掉了
CDH 竟然加了个参数 hive.insert.into.multilevel.dirs,默认是false,意思是我还有这BUG呢哈。
当你被坑了,想打个patch时,会发现改个配置就可以了。
意思是我保留这个BUG,但你要是被坑了也不能说我有BUG,自己改配置好了。$+@*^.!"?......
目前还没发现其他地方用到了这个参数,在这里唯一作用就是限制SQL中指定存放结果文件不存在的目录的深度不能大于1.
不过也没发现这有什么好处。

折腾半天,加个配置就可以了:

[html]  view plain copy print ?
  1. <property>  
  2.   <name>hive.insert.into.multilevel.dirs</name>  
  3.   <value>true</value>  
  4. </property>  
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值