HBASE-21962 Filters do not work in ThriftTable
This commit is contained in:
parent
4b0466b42c
commit
4d9ce7706b
|
@ -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 class ThriftUtilities {
|
public class ThriftUtilities {
|
||||||
|
|
||||||
|
@ -191,14 +193,8 @@ public 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,17 +590,22 @@ public 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());
|
||||||
|
@ -662,7 +663,7 @@ public 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);
|
||||||
}
|
}
|
||||||
|
@ -1227,7 +1228,7 @@ public 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
|
|
Loading…
Reference in New Issue