Repository: hbase
Updated Branches:
  refs/heads/branch-1 ea89047ab -> 27eab2c6e


HBASE-16356 REST API scanner: row prefix filter and custom filter parameters 
are mutually exclusive (Ben Watson)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/27eab2c6
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/27eab2c6
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/27eab2c6

Branch: refs/heads/branch-1
Commit: 27eab2c6ef0387fceeb6395f5c7d392ac43af57f
Parents: ea89047
Author: tedyu <[email protected]>
Authored: Wed May 10 06:05:25 2017 -0700
Committer: tedyu <[email protected]>
Committed: Wed May 10 06:05:25 2017 -0700

----------------------------------------------------------------------
 .../apache/hadoop/hbase/rest/TableResource.java | 33 ++++++++++----------
 .../apache/hadoop/hbase/rest/TestTableScan.java | 23 +++++++++++---
 2 files changed, 36 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/27eab2c6/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/TableResource.java
----------------------------------------------------------------------
diff --git 
a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/TableResource.java 
b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/TableResource.java
index 5671007..3a83b50 100644
--- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/TableResource.java
+++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/TableResource.java
@@ -135,14 +135,14 @@ public class TableResource extends ResourceBase {
       @DefaultValue(Long.MAX_VALUE + "") @QueryParam(Constants.SCAN_END_TIME) 
long endTime,
       @DefaultValue("true") @QueryParam(Constants.SCAN_BATCH_SIZE) boolean 
cacheBlocks,
       @DefaultValue("false") @QueryParam(Constants.SCAN_REVERSED) boolean 
reversed,
-      @DefaultValue("") @QueryParam(Constants.SCAN_FILTER) String filters) {
+      @DefaultValue("") @QueryParam(Constants.SCAN_FILTER) String paramFilter) 
{
     try {
-      Filter filter = null;
+      Filter prefixFilter = null;
       Scan tableScan = new Scan();
       if (scanSpec.indexOf('*') > 0) {
         String prefix = scanSpec.substring(0, scanSpec.indexOf('*'));
         byte[] prefixBytes = Bytes.toBytes(prefix);
-        filter = new PrefixFilter(Bytes.toBytes(prefix));
+        prefixFilter = new PrefixFilter(Bytes.toBytes(prefix));
         if (startRow.isEmpty()) {
           tableScan.setStartRow(prefixBytes);
         }
@@ -183,22 +183,23 @@ public class TableResource extends ResourceBase {
           tableScan.addFamily(Bytes.toBytes(familysplit[0]));
         }
       }
-      FilterList filterList = null;
-      if (StringUtils.isNotEmpty(filters)) {
-          ParseFilter pf = new ParseFilter();
-          Filter filterParam = pf.parseFilterString(filters);
-          if (filter != null) {
-            filterList = new FilterList(filter, filterParam);
-          }
-          else {
-            filter = filterParam;
-          }
+
+      FilterList filterList = new FilterList();
+      if (StringUtils.isNotEmpty(paramFilter)) {
+        ParseFilter pf = new ParseFilter();
+        Filter parsedParamFilter = pf.parseFilterString(paramFilter);
+        if (parsedParamFilter != null) {
+          filterList.addFilter(parsedParamFilter);
+        }
+        if (prefixFilter != null) {
+          filterList.addFilter(prefixFilter);
+        }
       }
-      if (filterList != null) {
+
+      if (filterList.getFilters().size() > 0) {
         tableScan.setFilter(filterList);
-      } else if (filter != null) {
-        tableScan.setFilter(filter);
       }
+
       int fetchSize = 
this.servlet.getConfiguration().getInt(Constants.SCAN_FETCH_SIZE, 10);
       tableScan.setCaching(fetchSize);
       tableScan.setReversed(reversed);

http://git-wip-us.apache.org/repos/asf/hbase/blob/27eab2c6/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableScan.java
----------------------------------------------------------------------
diff --git 
a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableScan.java 
b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableScan.java
index 874a390..0654f78 100644
--- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableScan.java
+++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableScan.java
@@ -468,7 +468,6 @@ public class TestTableScan {
   @Test
   public void testSimpleFilter() throws IOException, JAXBException {
     StringBuilder builder = new StringBuilder();
-    builder = new StringBuilder();
     builder.append("/*");
     builder.append("?");
     builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
@@ -490,9 +489,27 @@ public class TestTableScan {
   }
 
   @Test
+  public void testQualifierAndPrefixFilters() throws IOException, 
JAXBException {
+    StringBuilder builder = new StringBuilder();
+    builder.append("/abc*");
+    builder.append("?");
+    builder.append(Constants.SCAN_FILTER + "="
+        + URLEncoder.encode("QualifierFilter(=,'binary:1')", "UTF-8"));
+    Response response = 
+        client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
+    assertEquals(200, response.getCode());
+    JAXBContext ctx = JAXBContext.newInstance(CellSetModel.class);
+    Unmarshaller ush = ctx.createUnmarshaller();
+    CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
+    int count = TestScannerResource.countCellSet(model);
+    assertEquals(1, count);
+    assertEquals("abc", new 
String(model.getRows().get(0).getCells().get(0).getValue()));
+  }
+
+
+  @Test
   public void testCompoundFilter() throws IOException, JAXBException {
     StringBuilder builder = new StringBuilder();
-    builder = new StringBuilder();
     builder.append("/*");
     builder.append("?");
     builder.append(Constants.SCAN_FILTER + "="
@@ -511,7 +528,6 @@ public class TestTableScan {
   @Test
   public void testCustomFilter() throws IOException, JAXBException {
     StringBuilder builder = new StringBuilder();
-    builder = new StringBuilder();
     builder.append("/a*");
     builder.append("?");
     builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
@@ -531,7 +547,6 @@ public class TestTableScan {
   @Test
   public void testNegativeCustomFilter() throws IOException, JAXBException {
     StringBuilder builder = new StringBuilder();
-    builder = new StringBuilder();
     builder.append("/b*");
     builder.append("?");
     builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);

Reply via email to