如何将自定义过滤器从 HBase 0.94 转换为不使用任何原型的 HBase 0.98?
How to convert custom filter from HBase 0.94 to HBase 0.98 that doesnt use any protos?
我遇到超时,错误似乎来自我的自定义过滤器。错误如下:
Caused by: org.apache.hadoop.hbase.exceptions.DeserializationException: parseFrom called on base Filter, but should be called on derived type
我看到 Hbase 0.98 不再支持 write 和 readFields。目前我的write和readFields方法如下:
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)我现在需要使用 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。我们现在必须处理原始字节数组。例如要写一个 String 而不是利用 DataOutput.writeUTF 和 DataInput.readUTF,我们必须 "manually" 在字节数组中的字符串之前写一个 int 来知道即将到来的 String 涉及的字节数.
无论如何,执行我的 "manual" 字节数组处理以序列化和反序列化过滤器适用于 HBase 1.0.2 上的自定义过滤器。
我遇到超时,错误似乎来自我的自定义过滤器。错误如下:
Caused by: org.apache.hadoop.hbase.exceptions.DeserializationException: parseFrom called on base Filter, but should be called on derived type
我看到 Hbase 0.98 不再支持 write 和 readFields。目前我的write和readFields方法如下:
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)我现在需要使用 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。我们现在必须处理原始字节数组。例如要写一个 String 而不是利用 DataOutput.writeUTF 和 DataInput.readUTF,我们必须 "manually" 在字节数组中的字符串之前写一个 int 来知道即将到来的 String 涉及的字节数.
无论如何,执行我的 "manual" 字节数组处理以序列化和反序列化过滤器适用于 HBase 1.0.2 上的自定义过滤器。