You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by al...@apache.org on 2019/02/27 08:02:23 UTC
[hbase] branch branch-2 updated: HBASE-21962 Filters do not work in
ThriftTable
This is an automated email from the ASF dual-hosted git repository.
allan163 pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2 by this push:
new 4d9ce77 HBASE-21962 Filters do not work in ThriftTable
4d9ce77 is described below
commit 4d9ce7706bb9ca17463ae66bba3d105f1331de51
Author: Allan Yang <al...@apache.org>
AuthorDate: Wed Feb 27 16:00:04 2019 +0800
HBASE-21962 Filters do not work in ThriftTable
---
.../hadoop/hbase/thrift2/ThriftUtilities.java | 33 +++++++++++-----------
.../hadoop/hbase/thrift2/TestThriftConnection.java | 5 ++--
2 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftUtilities.java b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftUtilities.java
index ba85dc7..5c9853f 100644
--- a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftUtilities.java
+++ b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftUtilities.java
@@ -62,7 +62,6 @@ import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.filter.Filter;
-import org.apache.hadoop.hbase.filter.FilterBase;
import org.apache.hadoop.hbase.filter.ParseFilter;
import org.apache.hadoop.hbase.io.TimeRange;
import org.apache.hadoop.hbase.io.compress.Compression;
@@ -106,6 +105,9 @@ import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hbase.thirdparty.org.apache.commons.collections4.MapUtils;
+import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos;
+
@InterfaceAudience.Private
public class ThriftUtilities {
@@ -191,14 +193,8 @@ public class ThriftUtilities {
}
}
if (in.isSetFilterBytes()) {
- try {
- Filter filter = FilterBase.parseFrom(in.getFilterBytes());
- out.setFilter(filter);
- } catch (DeserializationException e) {
- throw new RuntimeException(e);
- }
+ out.setFilter(filterFromThrift(in.getFilterBytes()));
}
-
return out;
}
@@ -594,17 +590,22 @@ public class ThriftUtilities {
}
if (in.isSetFilterBytes()) {
- try {
- Filter filter = FilterBase.parseFrom(in.getFilterBytes());
- out.setFilter(filter);
- } catch (DeserializationException e) {
- throw new RuntimeException(e);
- }
+ out.setFilter(filterFromThrift(in.getFilterBytes()));
}
return out;
}
+ public static byte[] filterFromHBase(Filter filter) throws IOException {
+ FilterProtos.Filter filterPB = ProtobufUtil.toFilter(filter);
+ return filterPB.toByteArray();
+ }
+
+ public static Filter filterFromThrift(byte[] filterBytes) throws IOException {
+ FilterProtos.Filter filterPB = FilterProtos.Filter.parseFrom(filterBytes);
+ return ProtobufUtil.toFilter(filterPB);
+ }
+
public static TScan scanFromHBase(Scan in) throws IOException {
TScan out = new TScan();
out.setStartRow(in.getStartRow());
@@ -662,7 +663,7 @@ public class ThriftUtilities {
}
if (in.getFilter() != null) {
try {
- out.setFilterBytes(in.getFilter().toByteArray());
+ out.setFilterBytes(filterFromHBase(in.getFilter()));
} catch (IOException ioE) {
throw new RuntimeException(ioE);
}
@@ -1227,7 +1228,7 @@ public class ThriftUtilities {
}
if (in.getFilter() != null) {
try {
- out.setFilterBytes(in.getFilter().toByteArray());
+ out.setFilterBytes(filterFromHBase(in.getFilter()));
} catch (IOException ioE) {
throw new RuntimeException(ioE);
}
diff --git a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftConnection.java b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftConnection.java
index 1583619..2c9bf69 100644
--- a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftConnection.java
+++ b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftConnection.java
@@ -697,8 +697,8 @@ public class TestThriftConnection {
@Test
public void testScanWithFilters() throws Exception {
- testIteratorScanner(thriftConnection, "testScanWithFiltersTable");
- testIteratorScanner(thriftHttpConnection, "testScanWithFiltersHttpTable");
+ testScanWithFilters(thriftConnection, "testScanWithFiltersTable");
+ testScanWithFilters(thriftHttpConnection, "testScanWithFiltersHttpTable");
}
private void testScanWithFilters(Connection connection, String tableName) throws IOException {
@@ -712,6 +712,7 @@ public class TestThriftConnection {
filterList.addFilter(columnValueFilter);
Scan scan = new Scan();
scan.setMaxVersions(2);
+ scan.setFilter(filterList);
ResultScanner scanner = table.getScanner(scan);
Iterator<Result> iterator = scanner.iterator();
assertTrue(iterator.hasNext());