This is an automated email from the ASF dual-hosted git repository. wchevreuil pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/hbase.git
commit 904b555edcdbcc63926c5c01138afa55107dcbc2 Author: scotthunt <sch...@adobe.com> AuthorDate: Mon Dec 21 01:39:13 2020 -0700 HBASE-25084 Add "regexstringnocase" to ParseFilter for case-insensitivity (#2784) Signed-off-by: stack <st...@apache.org> Signed-off-by: Wellington Chevreuil <wchevre...@apache.org> --- .../org/apache/hadoop/hbase/filter/ParseConstants.java | 7 +++++++ .../java/org/apache/hadoop/hbase/filter/ParseFilter.java | 4 ++++ .../org/apache/hadoop/hbase/filter/TestParseFilter.java | 15 +++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/ParseConstants.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/ParseConstants.java index 9f52783..b9132a3 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/ParseConstants.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/ParseConstants.java @@ -245,6 +245,13 @@ public final class ParseConstants { 's','t','r','i','n','g'}; /** + * RegexStringNoCaseType byte array + */ + public static final byte [] regexStringNoCaseType = new byte [] {'r','e','g','e','x', + 's','t','r','i','n','g', + 'n','o','c','a','s','e'}; + + /** * SubstringType byte array */ public static final byte [] substringType = new byte [] {'s','u','b','s','t','r','i','n','g'}; diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/ParseFilter.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/ParseFilter.java index 1aeaa13..e06c6b5 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/ParseFilter.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/ParseFilter.java @@ -28,6 +28,7 @@ import java.util.Collections; import java.util.EmptyStackException; import java.util.HashMap; import java.util.Map; +import java.util.regex.Pattern; import java.util.Set; import java.util.Stack; @@ -812,6 +813,9 @@ public class ParseFilter { return new BinaryPrefixComparator(comparatorValue); else if (Bytes.equals(comparatorType, ParseConstants.regexStringType)) return new RegexStringComparator(new String(comparatorValue, StandardCharsets.UTF_8)); + else if (Bytes.equals(comparatorType, ParseConstants.regexStringNoCaseType)) + return new RegexStringComparator(new String(comparatorValue, StandardCharsets.UTF_8), + Pattern.CASE_INSENSITIVE | Pattern.DOTALL); else if (Bytes.equals(comparatorType, ParseConstants.substringType)) return new SubstringComparator(new String(comparatorValue, StandardCharsets.UTF_8)); else diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestParseFilter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestParseFilter.java index 8dd15be..fbedc1c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestParseFilter.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestParseFilter.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; import org.apache.hadoop.hbase.CompareOperator; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.MediumTests; @@ -280,6 +281,20 @@ public class TestParseFilter { } @Test + public void testQualifierFilterNoCase() throws IOException { + String filterString = "QualifierFilter(=, 'regexstringnocase:pre*')"; + QualifierFilter qualifierFilter = + doTestFilter(filterString, QualifierFilter.class); + assertEquals(CompareOperator.EQUAL, qualifierFilter.getCompareOperator()); + assertTrue(qualifierFilter.getComparator() instanceof RegexStringComparator); + RegexStringComparator regexStringComparator = + (RegexStringComparator) qualifierFilter.getComparator(); + assertEquals("pre*", new String(regexStringComparator.getValue(), StandardCharsets.UTF_8)); + int regexComparatorFlags = regexStringComparator.getEngine().getFlags(); + assertEquals(Pattern.CASE_INSENSITIVE | Pattern.DOTALL, regexComparatorFlags); + } + + @Test public void testValueFilter() throws IOException { String filterString = "ValueFilter(!=, 'substring:pre')"; ValueFilter valueFilter =