Hive使用过程有什么坑

这篇文章将为大家详细讲解有关Hive使用过程有什么坑,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

创新互联公司专业为企业提供新会网站建设、新会做网站、新会网站设计、新会网站制作等企业网站建设、网页设计与制作、新会企业网站模板建站服务,10余年新会做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

1. 在使用INSERT OVERWRITE DIRECTORY语句的时候报出如下异常

Caused by: java.io.IOException: Cannot get DistCp constructor: org.apache.hadoop.tools.DistCp.()
        at org.apache.hadoop.hive.shims.Hadoop23Shims.runDistCp(Hadoop23Shims.java:1160)
        at org.apache.hadoop.hive.common.FileUtils.copy(FileUtils.java:553)
        at org.apache.hadoop.hive.ql.metadata.Hive.moveFile(Hive.java:2622)
        ... 21 more

环境:hive-1.2.1 hadoop-2.7.2

错误原因:

hadoop-2.7.2源代码中org.apache.hadoop.tools.DistCp的无参构造方法已经取消public。

  /**
   * To be used with the ToolRunner. Not for public consumption.
   */
  @VisibleForTesting
  DistCp() {}

而hive-1.2.1中使用反射机制初始化org.apache.hadoop.tools.DistCp时,调用的正是无参构造方法。

@Override
  public boolean runDistCp(Path src, Path dst, Configuration conf) throws IOException {
    int rc;

    // Creates the command-line parameters for distcp
    String[] params = {"-update", "-skipcrccheck", src.toString(), dst.toString()};

    try {
      Class clazzDistCp = Class.forName("org.apache.hadoop.tools.DistCp");
      Constructor c = clazzDistCp.getConstructor();
      c.setAccessible(true);
      Tool distcp = (Tool)c.newInstance();
      distcp.setConf(conf);
      rc = distcp.run(params);
    } catch (ClassNotFoundException e) {
      throw new IOException("Cannot find DistCp class package: " + e.getMessage());
    } catch (NoSuchMethodException e) {
      throw new IOException("Cannot get DistCp constructor: " + e.getMessage());
    } catch (Exception e) {
      throw new IOException("Cannot execute DistCp process: " + e, e);
    }

    return (0 == rc);
  }

解决方案:使用老版本的hadoop-distcp-x.x.x.jar,我这里使用的是hadoop-distcp-2.6.2.jar。

  @VisibleForTesting
  public DistCp() {}

关于“Hive使用过程有什么坑”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


当前标题:Hive使用过程有什么坑
网站链接:http://myzitong.com/article/ggjjsj.html