public class TestHBaseRegexParser extends DrillTest {
@Test
public void testLikeExprToRegex() throws Exception {
HBaseRegexParser parser = new HBaseRegexParser("ABC%[0-7][0-9A-Fa-f]").parse();
assertEquals("^\\QABC\\E.*[0-7][0-9A-Fa-f]$", parser.getRegexString());
assertEquals("ABC", parser.getPrefixString());
Pattern pattern = Pattern.compile(parser.getRegexString(), Pattern.DOTALL);
assertTrue(pattern.matcher("ABC79").matches());
assertTrue(pattern.matcher("ABCxxxxxxx79").matches());
parser = new HBaseRegexParser("ABC%[0-8]%_").parse();
assertEquals("^\\QABC\\E.*[0-8].*.$", parser.getRegexString());
assertEquals("ABC", parser.getPrefixString());
pattern = Pattern.compile(parser.getRegexString(), Pattern.DOTALL);
assertTrue(pattern.matcher("ABC79").matches());
assertTrue(pattern.matcher("ABCxxxx79").matches());
assertTrue(pattern.matcher("ABCxxxx7xxxxx9").matches());
assertTrue(pattern.matcher("ABC[0-8]_").matches());
parser = new HBaseRegexParser("ABC%[0-8]%_", '%').parse();
assertEquals("^\\QABC\\E\\Q[\\E\\Q0-8]\\E\\Q_\\E$", parser.getRegexString());
assertEquals("ABC[0-8]_", parser.getPrefixString());
pattern = Pattern.compile(parser.getRegexString(), Pattern.DOTALL);
assertFalse(pattern.matcher("ABC79").matches());
assertTrue(pattern.matcher("ABC[0-8]_").matches());
try {
parser = new HBaseRegexParser("ABC%[0-8][^a-f]%", '%').parse();
fail("Parsed an illegal LIKE expression.");
} catch (IllegalArgumentException e) {
}
}