private boolean evaluateLikePredicate(LikePredicate node, Slice value, Regex regex) { if (type(node.getValue()) instanceof VarcharType) { return LikeFunctions.likeVarchar(value, regex); } Type type = type(node.getValue()); checkState(type instanceof CharType, "LIKE value is neither VARCHAR or CHAR"); return LikeFunctions.likeChar((long) ((CharType) type).getLength(), value, regex); }
@Test public void testLikeChar() { Regex regex = likePattern(utf8Slice("f%b__")); assertTrue(likeChar(6L, utf8Slice("foobar"), regex)); assertTrue(likeChar(6L, utf8Slice("foob"), regex)); assertFalse(likeChar(7L, utf8Slice("foob"), regex)); assertFunction("cast('foob' as char(6)) LIKE 'f%b__'", BOOLEAN, true); assertFunction("cast('foob' as char(7)) LIKE 'f%b__'", BOOLEAN, false); }