Java 如何将自定义筛选器从HBase 0.94转换为不使用任何protos的HBase 0.98?

Java 如何将自定义筛选器从HBase 0.94转换为不使用任何protos的HBase 0.98?,java,hbase,Java,Hbase,我收到超时,错误似乎来自我的自定义筛选器。错误如下: Caused by: org.apache.hadoop.hbase.exceptions.DeserializationException: parseFrom called on base Filter, but should be called on derived type 我发现Hbase 0.98不再支持写入和读取字段。目前,我对写入和读取字段的方法如下: public MyCustomFilter(Schema first)

我收到超时,错误似乎来自我的自定义筛选器。错误如下:

Caused by: org.apache.hadoop.hbase.exceptions.DeserializationException: parseFrom called on base Filter, but should be called on derived type
我发现Hbase 0.98不再支持写入和读取字段。目前,我对写入和读取字段的方法如下:

 public MyCustomFilter(Schema first) {
     this.schema = first;
     filterNow();
 }

public void write(DataOutput o) throws IOException {
  byte[] firstBytes = Bytes.toBytes(first.toString());
  out.writeInt(firstBytes.length)
}

public void readFields(DataInput i) throws IOException {
  int firstLength = i.readInt();
  byte firstBytes = new byte[firstLength];
  i.readFully(firstBytes, 0, firstLength);
  this.first = new Schema.Parser().parse(new ByteArrayINputStream(firstBytes);
  filterNow();
}

private void filterNow() {
   FilterQueryParser parser = new FilterQueryParser(first);
   ....
}
Cloudera似乎认为这只是迁移这些方法的问题:

FilterBase no longer implements Writable. This means that you do not need to implement readFields() and write() methods when writing your own custom fields. Instead, put this logic into the toByteArray and parseFrom methods. See this page for an example.
但是,SingleColumnValueFilter提供的示例似乎使用了Filter.Protos中的ProtoBufs,它似乎包含一个SingleColumnValueFilter,它是HBase的核心。。。我的CustomFilter没有使用这种类型的东西,我根本没有使用protobufs。
有没有办法将我所拥有的转化为hbase 0.98所带来的快乐?O(Schema.parser是avro)r我现在需要使用Filter.Protos吗?如果是,如何实现?

您必须实现方法
public byte[]toByteArray()
而不是
public void write(DataOutput o)
来序列化客户端上的筛选器实例,以便发送到HBase服务器端

类似地,您必须实现方法
public static Filter parseFrom(final byte[]pbBytes)
而不是
public void readFields(DataInput i)
,以便可以在服务器端读取字节流,并通过HBase在过滤器实例中进行翻译

不幸的是,我们似乎丢失了0.94中可用的有用对象DataInput和DataOutput。我们现在必须处理原始字节数组。例如,要编写字符串而不是利用DataOutput.writeUTF和DataInput.readUTF,我们必须“手动”在字节数组中的字符串之前写入一个int,以了解即将到来的字符串所涉及的字节数

无论如何,在HBase 1.0.2上对自定义筛选器进行序列化和反序列化的“手动”字节数组处理是可行的