csun5285 commented on code in PR #68133:
URL: https://github.com/apache/doris/pull/68133#discussion_r4035893384
##########
be/test/exprs/function/function_like_test.cpp:
##########
@@ -144,6 +144,84 @@ TEST(FunctionLikeTest, like) {
func_name, const_pattern_input_types, data_set));
}
+TEST(FunctionLikeTest, like_matches_whole_value) {
+ std::string func_name = "like";
+
+ DataSet data_set = {
+ // A trailing newline belongs to the value, so a pattern that is
anchored at the
+ // tail must not match across it.
+ {{std::string("acb"), std::string("a_b")}, uint8_t(1)},
+ {{std::string("acb\n"), std::string("a_b")}, uint8_t(0)},
+ {{std::string("acb\r\n"), std::string("a_b")}, uint8_t(0)},
+ {{std::string("acb\n\n"), std::string("a_b")}, uint8_t(0)},
+ {{std::string("acbx"), std::string("a_b")}, uint8_t(0)},
+ {{std::string("\nacb"), std::string("a_b")}, uint8_t(0)},
+ {{std::string("abc"), std::string("a%c")}, uint8_t(1)},
+ {{std::string("abc\n"), std::string("a%c")}, uint8_t(0)},
+ {{std::string("abc\n"), std::string("%b%c")}, uint8_t(0)},
+ // The newline is an ordinary character for '_' and '%'.
+ {{std::string("a\nb"), std::string("a_b")}, uint8_t(1)},
+ {{std::string("a\nb"), std::string("a%b")}, uint8_t(1)},
+ {{std::string("acb\n"), std::string("a_b_")}, uint8_t(1)},
+ {{std::string("acb\n"), std::string("a_b%")}, uint8_t(1)},
+ {{std::string("abc\n"), std::string("a_c%")}, uint8_t(1)},
+ // '_' stands for one character, not for one byte.
+ {{std::string("a中b"), std::string("a_b")}, uint8_t(1)},
+ {{std::string("a中b\n"), std::string("a_b")}, uint8_t(0)},
+ // An empty pattern only matches an empty value.
+ {{std::string(""), std::string("")}, uint8_t(1)},
+ {{std::string("\n"), std::string("")}, uint8_t(0)},
+ // The shortcut paths and the regex path must agree on the same
value.
+ {{std::string("acb\n"), std::string("acb")}, uint8_t(0)},
+ {{std::string("abc\n"), std::string("%c")}, uint8_t(0)},
+ {{std::string("abc\n"), std::string("a%")}, uint8_t(1)},
+ // A pattern open at the tail must not make the engines walk the
rest of the value:
+ // `.*` only matches valid UTF-8, so anchoring it with `\z` would
make RE2 reject a
+ // value whose tail is not valid UTF-8 while Hyperscan still
accepts it.
+ {{std::string("acb\xff", 4), std::string("a_b%")}, uint8_t(1)},
Review Comment:
已删除
##########
be/src/exprs/function/like.cpp:
##########
@@ -809,6 +810,10 @@ void FunctionLike::convert_like_pattern(const
LikeSearchState* state, const std:
}
if (c == '%') {
+ if (i + 1 == pattern.size()) {
+ // a trailing `%` matches anything, and so does appending
nothing
+ return;
+ }
re_pattern->append(".*");
Review Comment:
已删除
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]