HBASE-21962 Filters do not work in ThriftTable

This commit is contained in:
Allan Yang 2019-02-27 15:56:25 +08:00
parent 6e06a0d790
commit 8408e26d26
2 changed files with 20 additions and 18 deletions

View File

@ -62,7 +62,6 @@ import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.exceptions.DeserializationException; import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.filter.Filter; 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.filter.ParseFilter;
import org.apache.hadoop.hbase.io.TimeRange; import org.apache.hadoop.hbase.io.TimeRange;
import org.apache.hadoop.hbase.io.compress.Compression; 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.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 @InterfaceAudience.Private
public final class ThriftUtilities { public final class ThriftUtilities {
@ -191,14 +193,8 @@ public final class ThriftUtilities {
} }
} }
if (in.isSetFilterBytes()) { if (in.isSetFilterBytes()) {
try { out.setFilter(filterFromThrift(in.getFilterBytes()));
Filter filter = FilterBase.parseFrom(in.getFilterBytes());
out.setFilter(filter);
} catch (DeserializationException e) {
throw new RuntimeException(e);
} }
}
return out; return out;
} }
@ -599,17 +595,22 @@ public final class ThriftUtilities {
} }
if (in.isSetFilterBytes()) { if (in.isSetFilterBytes()) {
try { out.setFilter(filterFromThrift(in.getFilterBytes()));
Filter filter = FilterBase.parseFrom(in.getFilterBytes());
out.setFilter(filter);
} catch (DeserializationException e) {
throw new RuntimeException(e);
}
} }
return out; 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 { public static TScan scanFromHBase(Scan in) throws IOException {
TScan out = new TScan(); TScan out = new TScan();
out.setStartRow(in.getStartRow()); out.setStartRow(in.getStartRow());
@ -667,7 +668,7 @@ public final class ThriftUtilities {
} }
if (in.getFilter() != null) { if (in.getFilter() != null) {
try { try {
out.setFilterBytes(in.getFilter().toByteArray()); out.setFilterBytes(filterFromHBase(in.getFilter()));
} catch (IOException ioE) { } catch (IOException ioE) {
throw new RuntimeException(ioE); throw new RuntimeException(ioE);
} }
@ -1232,7 +1233,7 @@ public final class ThriftUtilities {
} }
if (in.getFilter() != null) { if (in.getFilter() != null) {
try { try {
out.setFilterBytes(in.getFilter().toByteArray()); out.setFilterBytes(filterFromHBase(in.getFilter()));
} catch (IOException ioE) { } catch (IOException ioE) {
throw new RuntimeException(ioE); throw new RuntimeException(ioE);
} }

View File

@ -697,8 +697,8 @@ public class TestThriftConnection {
@Test @Test
public void testScanWithFilters() throws Exception { public void testScanWithFilters() throws Exception {
testIteratorScanner(thriftConnection, "testScanWithFiltersTable"); testScanWithFilters(thriftConnection, "testScanWithFiltersTable");
testIteratorScanner(thriftHttpConnection, "testScanWithFiltersHttpTable"); testScanWithFilters(thriftHttpConnection, "testScanWithFiltersHttpTable");
} }
private void testScanWithFilters(Connection connection, String tableName) throws IOException { private void testScanWithFilters(Connection connection, String tableName) throws IOException {
@ -712,6 +712,7 @@ public class TestThriftConnection {
filterList.addFilter(columnValueFilter); filterList.addFilter(columnValueFilter);
Scan scan = new Scan(); Scan scan = new Scan();
scan.setMaxVersions(2); scan.setMaxVersions(2);
scan.setFilter(filterList);
ResultScanner scanner = table.getScanner(scan); ResultScanner scanner = table.getScanner(scan);
Iterator<Result> iterator = scanner.iterator(); Iterator<Result> iterator = scanner.iterator();
assertTrue(iterator.hasNext()); assertTrue(iterator.hasNext());