hive -f 文件内容里的注释引发小Bug

问题记录

run.hql 文件内容如下

-- line1
  -- line2 ;
select 1;

或者

-- line1
  -- line2

在执行 hive -f run.hql 时会报错,原因是第二行没有作为注释 被过滤掉,当正常代码执行

查看Hive源码

https://github.com/apache/hive/blob/master/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java

第7行
public int processReader(BufferedReader r) throws IOException {
    String line;
    StringBuilder qsb = new StringBuilder();

    while ((line = r.readLine()) != null) {
      // Skipping through comments
      // 出问题的地方,应该是 line.trim().startsWith("--")
      if (! line.startsWith("--")) {
        qsb.append(line + "\n");
      }
    }

    return (processLine(qsb.toString()));
  }

需要先将 空格 先去除

发布了53 篇原创文章 · 获赞 50 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/xw514124202/article/details/102836607
今日推荐