Hive导入失败[java.lang.OutOfMemoryError]

时间:2017-07-19 12:39:03

标签: java hive hortonworks-data-platform ambari

我正在使用bash命令将hql数据库导入hive客户端节点(使用Hortonworks数据平台)上的hive数据库:

$ hive -f tables.sql

我收到错误:

log4j:WARN No such property [maxFileSize] in org.apache.log4j.DailyRollingFileAppender.

Logging initialized using configuration in file:/etc/hive/2.6.1.0-129/0/hive-log4j.properties
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:3332)
    at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
    at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:448)
    at java.lang.StringBuilder.append(StringBuilder.java:136)
    at org.apache.hadoop.hive.cli.CliDriver.processReader(CliDriver.java:409)
    at org.apache.hadoop.hive.cli.CliDriver.processFile(CliDriver.java:429)
    at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:718)
    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:685)
    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:625)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:233)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:148)

我尝试将HADOOP_HEAPSIZE从1GB增加到4 GB但我仍然得到错误。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

OutOfMemoryError来自CliDriver#processReader(BufferedReader)中的Hive代码库。

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

  while ((line = r.readLine()) != null) {
    // Skipping through comments
    if (! line.startsWith("--")) {
      qsb.append(line + "\n");
    }
  }

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

它将从文件中读取的所有行添加到StringBuilder然后执行它。这必须意味着您指定的输入文件非常大。是否可以将其拆分为多个较小的文件并分别执行,以减少内存占用量?

您提到这是SQL数据库的导入。 Apache Sqoop可能更适合该用例。