我正在尝试使用 HBase 版本 0.98.0-hadoop2 写入 Java 中的 HBase 表。在我使用的之前的版本(0.94.x-hadoop1)中,Put实现了Writable接口(interface),可以在reducer中使用,以如下方式写入hbase表:
Put row = new Put(Bytes.toBytes(unique_row_identifier));
put.add(family_bytes, qualifier_bytes, value_bytes);
... // other put.adds to the same row
context.write(null, put);\n
当使用升级后的 jar(版本 0.98.0-hadoop2)时,所有带有 context.write(null, row) 的行都会出现错误,并显示消息“不兼容的类型:Put 无法转换为 Writable”。稍作研究,Put对象在0.94.0版本实现了Writable,但在0.98.0版本不再实现该接口(interface)。
还有其他方法可以从 reducer 写入 hbase 表吗?应该使用这个版本的hbase吗?
欢迎提出任何建议。
谢谢
最佳答案
您是否使用 TableOutputFormat 作为作业输出格式?在 0.94.x 中,TableOutputFormat 是对 OutputFormat 的扩展。在 0.98 中,TableOutputFormat 是对 OutputFormat 的扩展。所以 context.write(null, put);应该在 0.98 中编译得很好,因为 Put 是 extends Mutation。确保你的 hbase 依赖是正确的。
关于java - 使用版本 0.98.0-hadoop2 写入 HBase 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24760547/