扩展 HBase Put 的问题
我在尝试扩展 HBase Put 类时遇到问题。
我有这样的代码
public class HBasePut extends Put {
//here i define my own adds because i have only string "keys"
//so i dont have to use Bytes.toBytes() every time and so on
}
但是当测试这些类时,这个代码是可以的:
Put p = new Put(Bytes.toBytes('row'));
p.add(Bytes.toBytes('cf'), Bytes.toBytes('col'), Bytes.toBytes(1));
users.put(p);
但是这个在尝试大约 70 秒后出现异常 - RetriesExhaustedWithDetailsException
HBasePut p = new HBasePut('row');
p.add('cf', 'col', 1);
users.put(p);
所以我尝试迭代 RetriesExh 中的异常...它告诉我有一个异常,但是它为空...
我正在查看 Put、HTable 和 HConnection 的代码,但找不到在 HBase 中准确编写 Put 类的任何依赖项,所以我不知道为什么我的 HBasePut 不起作用。
是否有可能以某种方式扩展 Put ? 谢谢
I have a problem while trying to extend HBase Put class.
I have a code like this
public class HBasePut extends Put {
//here i define my own adds because i have only string "keys"
//so i dont have to use Bytes.toBytes() every time and so on
}
But when testing these classes this code is OK:
Put p = new Put(Bytes.toBytes('row'));
p.add(Bytes.toBytes('cf'), Bytes.toBytes('col'), Bytes.toBytes(1));
users.put(p);
But this one makes an exception after about 70 seconds of trying - RetriesExhaustedWithDetailsException
HBasePut p = new HBasePut('row');
p.add('cf', 'col', 1);
users.put(p);
So I tried to iterate over exceptions in RetriesExh... It tells me there is one exception but it is null...
I was looking at the code of Put, HTable and HConnection but I couldn't find any dependencies on writing exactly the class Put in HBase so I don't know why my HBasePut is not working.
Is it possible to extend Put somehow?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您查看区域服务器日志,您将看到类似“找不到类... HBasePut”的异常。因此,HBase 显然将 Put 实例从客户端传输到服务器,但服务器不知道您的子类并且无法处理它。
我建议不要子类化,而是建议编写一个自定义 Util 类,该类提供静态“add”方法,将 Put 实例和 Strings 作为参数,并使用静态导入来导入此方法。
If you look into your regionserver logs you will see an exception like "Can't find class ... HBasePut". So, HBase obviously transports a Put instance from client to server, but the server is unaware of your subclass and cannot process it.
I suggest refraining from subclassing and instead suggest to code a custom Util class which provides a static "add" method taking the Put instance and Strings as args and importing this method with a static import.
正如 zillion1 所说,只需使用静态方法:
As zillion1 said, just use a static method: