从 Hbase 导出数据时出现数字格式异常

Number Format Exception while Exporting data from Hbase

我计划通过在 hbase 中提及 starttimeendtime 来导出 table。由于我是新手,所以我假设开始时间和结束时间是与行一起插入的时间戳。

我的 table 包括:

ROW        COLUMN+CELL
 1         column=d:A, timestamp=1439284609013, value=HHHH
 1         column=d:B, timestamp=1439284620216, value=HHHH111
 2         column=d:A, timestamp=1439284637133, value=HHHH
 2         column=d:B, timestamp=1439284641872, value=HHHH111
 3         column=d:A, timestamp=1439284646830, value=HHHH
 3         column=d:B, timestamp=1439284651527, value=HHHH111
 3         column=d:C, timestamp=1439284665492, value=HHHH

我执行了:

hbase org.apache.hadoop.hbase.mapreduce.Export emp1 ~/KT/bkp 1439284609013 1439284641872

我得到了:

Exception in thread "main" java.lang.NumberFormatException: For input string: "1439284609013"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:495)
    at java.lang.Integer.parseInt(Integer.java:527)
    at org.apache.hadoop.hbase.mapreduce.Export.getConfiguredScanForJob(Export.java:112)
    at org.apache.hadoop.hbase.mapreduce.Export.createSubmittableJob(Export.java:96)
    at org.apache.hadoop.hbase.mapreduce.Export.main(Export.java:201)

帮我做什么

异常的确切原因是数字 1439284609013 太大而不适合 Integer

然而,实际问题出在其他地方。我看了源码,你的参数好像不对:

emp1 ~/KT/bkp 1439284609013 1439284641872

你给了一个String,另一个String和两个Long,这些是

  • args[0]: tableName
  • args[1]: outputDir
  • args[2]: startTime
  • args[3]: endTime

问题是,您缺少一个参数:args[2] 应该是 IntegerstartTime 应该变成 args[3]endTime 应该变成 args[4].

在源代码中,预期的第三个 Integer 参数称为 versions,但我不完全知道那是什么意思。


官方文档

查看源代码是一回事,但 official docs 还给出了 Export 的语法如下:

$ bin/hbase org.apache.hadoop.hbase.mapreduce.Export <tablename> <outputdir> [<versions> [<starttime> [<endtime>]]]

By default, the Export tool only exports the newest version of a given cell, regardless of the number of versions stored. To export more than one version, replace <versions> with the desired number of versions.


总结一下

要实现您最初想要的,只需添加 1 作为第三个参数:

hbase org.apache.hadoop.hbase.mapreduce.Export emp1 ~/KT/bkp 1 1439284609013 1439284641872

时间戳通常与具有 64 位的 Long 类型相关联

整数有32位,范围只有-2,147,483,648到2,147,483,647 Java

我只输入了开始时间和结束时间。导出需要开始和结束时间之前的版本。所以最后我输入了它有效的版本号。

./hbase org.apache.hadoop.hbase.mapreduce.Export emp1 ~/KT/bkp 2147483647 1439284609013 1439284646830