HBASE-21962 Filters do not work in ThriftTable
This commit is contained in:
parent
6e06a0d790
commit
8408e26d26
|
@ -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 final class ThriftUtilities {
|
||||
|
||||
|
@ -191,14 +193,8 @@ public final 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;
|
||||
}
|
||||
|
||||
|
@ -599,17 +595,22 @@ public final 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());
|
||||
|
@ -667,7 +668,7 @@ public final class ThriftUtilities {
|
|||
}
|
||||
if (in.getFilter() != null) {
|
||||
try {
|
||||
out.setFilterBytes(in.getFilter().toByteArray());
|
||||
out.setFilterBytes(filterFromHBase(in.getFilter()));
|
||||
} catch (IOException ioE) {
|
||||
throw new RuntimeException(ioE);
|
||||
}
|
||||
|
@ -1232,7 +1233,7 @@ public final class ThriftUtilities {
|
|||
}
|
||||
if (in.getFilter() != null) {
|
||||
try {
|
||||
out.setFilterBytes(in.getFilter().toByteArray());
|
||||
out.setFilterBytes(filterFromHBase(in.getFilter()));
|
||||
} catch (IOException ioE) {
|
||||
throw new RuntimeException(ioE);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue