简体   繁体   English

扩展HBase Put的问题

[英]Problem with extending HBase Put

I have a problem while trying to extend HBase Put class. 尝试扩展HBase Put类时遇到问题。

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 但是,经过约70秒钟的尝试,此异常成为异常-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... 因此,我尝试遍历RetriesExh中的异常...它告诉我有一个异常,但它为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. 我当时在看Put,HTable和HConnection的代码,但找不到与完全在HBase中编写Put类有关的任何依存关系,所以我不知道为什么我的HBasePut无法正常工作。

Is it possible to extend Put somehow? 是否可以某种方式扩展Put? Thank you 谢谢

If you look into your regionserver logs you will see an exception like "Can't find class ... HBasePut". 如果查看regionserver日志,则会看到类似“找不到类... HBasePut”的异常。 So, HBase obviously transports a Put instance from client to server, but the server is unaware of your subclass and cannot process it. 因此,HBase显然将Put实例从客户端传输到服务器,但是服务器不知道您的子类,因此无法对其进行处理。

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. 我建议不要进行子类化,而建议编写一个自定义的Util类,该类提供一个以Put实例和Strings为args的静态“ add”方法,并通过静态导入方式导入此方法。

As zillion1 said, just use a static method: 正如zillion1所说,只需使用静态方法:

public static void add(Put put, String col, String qual, String data)
{
  put.add(col.getBytes(), qual.getBytes(), data.getBytes());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM