You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2017/05/09 14:57:54 UTC
hbase git commit: HBASE-16356 REST API scanner: row prefix filter and
custom filter parameters are mutually exclusive (Ben Watson)
Repository: hbase
Updated Branches:
refs/heads/master 51d4c68b7 -> ac1024af2
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/ac1024af
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/ac1024af
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/ac1024af
Branch: refs/heads/master
Commit: ac1024af213158d6528ffec964f2bf4aadd9ccd3
Parents: 51d4c68
Author: tedyu <yu...@gmail.com>
Authored: Tue May 9 07:58:20 2017 -0700
Committer: tedyu <yu...@gmail.com>
Committed: Tue May 9 07:58:20 2017 -0700
----------------------------------------------------------------------
.../apache/hadoop/hbase/filter/FilterList.java | 2 +-
.../apache/hadoop/hbase/rest/TableResource.java | 31 +++++++++---------
.../apache/hadoop/hbase/rest/TestTableScan.java | 33 ++++++++++++++------
3 files changed, 39 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/ac1024af/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FilterList.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FilterList.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FilterList.java
index d533026..0742b22 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FilterList.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FilterList.java
@@ -148,7 +148,7 @@ final public class FilterList extends FilterBase {
return filters;
}
- private int size() {
+ public int size() {
return filters.size();
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/ac1024af/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 9eb21ec..3019e40 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,21 @@ 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.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/ac1024af/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 96b9c4a..c674b3c 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
@@ -30,7 +30,6 @@ import java.io.Serializable;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import javax.ws.rs.core.MediaType;
@@ -94,7 +93,7 @@ public class TestTableScan {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
conf = TEST_UTIL.getConfiguration();
- conf.set(Constants.CUSTOM_FILTERS, "CustomFilter:" + CustomFilter.class.getName());
+ conf.set(Constants.CUSTOM_FILTERS, "CustomFilter:" + CustomFilter.class.getName());
TEST_UTIL.startMiniCluster();
REST_TEST_UTIL.startServletContainer(conf);
client = new Client(new Cluster().add("localhost",
@@ -146,7 +145,7 @@ public class TestTableScan {
response = client.get("/" + TABLE + builder.toString(),
Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
- assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
+ assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
model = (CellSetModel) ush.unmarshal(response.getStream());
count = TestScannerResource.countCellSet(model);
assertEquals(expectedRows1, count);
@@ -466,11 +465,10 @@ public class TestTableScan {
int count = TestScannerResource.countCellSet(model);
assertEquals(0, count);
}
-
+
@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);
@@ -492,9 +490,26 @@ 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 + "="
@@ -513,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);
@@ -529,11 +543,10 @@ public class TestTableScan {
assertEquals(1, count);
assertEquals("abc", new String(model.getRows().get(0).getCells().get(0).getValue()));
}
-
+
@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);
@@ -606,7 +619,7 @@ public class TestTableScan {
public CustomFilter(byte[] key) {
super(key);
}
-
+
@Override
public boolean filterRowKey(byte[] buffer, int offset, int length) {
int cmp = Bytes.compareTo(buffer, offset, length, this.key, 0, this.key.length);