HBASE-25084 Add "regexstringnocase" to ParseFilter for case-insensitivity (#2784)
Signed-off-by: stack <stack@apache.org> Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
This commit is contained in:
parent
e250c7fc63
commit
e9c45a1353
|
@ -246,6 +246,13 @@ public final class ParseConstants {
|
||||||
public static final byte [] regexStringType = new byte [] {'r','e','g','e', 'x',
|
public static final byte [] regexStringType = new byte [] {'r','e','g','e', 'x',
|
||||||
's','t','r','i','n','g'};
|
'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
|
* SubstringType byte array
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -36,6 +36,7 @@ import java.util.Collections;
|
||||||
import java.util.EmptyStackException;
|
import java.util.EmptyStackException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
|
@ -813,6 +814,9 @@ public class ParseFilter {
|
||||||
return new BinaryPrefixComparator(comparatorValue);
|
return new BinaryPrefixComparator(comparatorValue);
|
||||||
else if (Bytes.equals(comparatorType, ParseConstants.regexStringType))
|
else if (Bytes.equals(comparatorType, ParseConstants.regexStringType))
|
||||||
return new RegexStringComparator(new String(comparatorValue, StandardCharsets.UTF_8));
|
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))
|
else if (Bytes.equals(comparatorType, ParseConstants.substringType))
|
||||||
return new SubstringComparator(new String(comparatorValue, StandardCharsets.UTF_8));
|
return new SubstringComparator(new String(comparatorValue, StandardCharsets.UTF_8));
|
||||||
else
|
else
|
||||||
|
|
|
@ -21,8 +21,10 @@ package org.apache.hadoop.hbase.filter;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
@ -271,6 +273,20 @@ public class TestParseFilter {
|
||||||
assertEquals("pre*", new String(regexStringComparator.getValue()));
|
assertEquals("pre*", new String(regexStringComparator.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testQualifierFilterNoCase() throws IOException {
|
||||||
|
String filterString = "QualifierFilter(=, 'regexstringnocase:pre*')";
|
||||||
|
QualifierFilter qualifierFilter =
|
||||||
|
doTestFilter(filterString, QualifierFilter.class);
|
||||||
|
assertEquals(CompareFilter.CompareOp.EQUAL, qualifierFilter.getOperator());
|
||||||
|
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
|
@Test
|
||||||
public void testValueFilter() throws IOException {
|
public void testValueFilter() throws IOException {
|
||||||
String filterString = "ValueFilter(!=, 'substring:pre')";
|
String filterString = "ValueFilter(!=, 'substring:pre')";
|
||||||
|
@ -655,11 +671,11 @@ public class TestParseFilter {
|
||||||
FirstKeyOnlyFilter firstKeyOnlyFilter =
|
FirstKeyOnlyFilter firstKeyOnlyFilter =
|
||||||
doTestFilter(filterString, FirstKeyOnlyFilter.class);
|
doTestFilter(filterString, FirstKeyOnlyFilter.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegisterFilter() {
|
public void testRegisterFilter() {
|
||||||
ParseFilter.registerFilter("MyFilter", "some.class");
|
ParseFilter.registerFilter("MyFilter", "some.class");
|
||||||
|
|
||||||
assertTrue(f.getSupportedFilters().contains("MyFilter"));
|
assertTrue(f.getSupportedFilters().contains("MyFilter"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue