diff --git a/cpp/src/gandiva/like_holder.cc b/cpp/src/gandiva/like_holder.cc index 48e390f197f7c..05e03b51aa8ed 100644 --- a/cpp/src/gandiva/like_holder.cc +++ b/cpp/src/gandiva/like_holder.cc @@ -80,8 +80,9 @@ Status LikeHolder::Make(const FunctionNode& node, std::shared_ptr* h !IsArrowStringLiteral(literal_type), Status::Invalid( "'like' function requires a string literal as the second parameter")); + + RE2::Options regex_op; if (node.descriptor()->name() == "ilike") { - RE2::Options regex_op; regex_op.set_case_sensitive(false); // set case-insensitive for ilike function. return Make(arrow::util::get(literal->holder()), holder, regex_op); @@ -143,12 +144,17 @@ Status LikeHolder::Make(const std::string& sql_pattern, std::string pcre_pattern; ARROW_RETURN_NOT_OK(RegexUtil::SqlLikePatternToPcre(sql_pattern, pcre_pattern)); - auto lholder = std::shared_ptr(new LikeHolder(pcre_pattern, regex_op)); + std::shared_ptr lholder; + if (regex_op.case_sensitive()) { + lholder = std::shared_ptr(new LikeHolder(pcre_pattern)); + } else { + lholder = std::shared_ptr(new LikeHolder(pcre_pattern, regex_op)); + } + ARROW_RETURN_IF(!lholder->regex_.ok(), Status::Invalid("Building RE2 pattern '", pcre_pattern, "' failed")); *holder = lholder; return Status::OK(); } - } // namespace gandiva diff --git a/cpp/src/gandiva/like_holder.h b/cpp/src/gandiva/like_holder.h index 8c83200fc4c79..73e58017de19f 100644 --- a/cpp/src/gandiva/like_holder.h +++ b/cpp/src/gandiva/like_holder.h @@ -54,7 +54,7 @@ class GANDIVA_EXPORT LikeHolder : public FunctionHolder { private: explicit LikeHolder(const std::string& pattern) : pattern_(pattern), regex_(pattern) {} - explicit LikeHolder(const std::string& pattern, RE2::Options regex_op) + LikeHolder(const std::string& pattern, RE2::Options regex_op) : pattern_(pattern), regex_(pattern, regex_op) {} std::string pattern_; // posix pattern string, to help debugging diff --git a/cpp/src/gandiva/like_holder_test.cc b/cpp/src/gandiva/like_holder_test.cc index 342f3c56c172f..a52533a113836 100644 --- a/cpp/src/gandiva/like_holder_test.cc +++ b/cpp/src/gandiva/like_holder_test.cc @@ -27,6 +27,7 @@ namespace gandiva { class TestLikeHolder : public ::testing::Test { public: + RE2::Options regex_op; FunctionNode BuildLike(std::string pattern) { auto field = std::make_shared(arrow::field("in", arrow::utf8())); auto pattern_node = @@ -48,7 +49,7 @@ class TestLikeHolder : public ::testing::Test { TEST_F(TestLikeHolder, TestMatchAny) { std::shared_ptr like_holder; - auto status = LikeHolder::Make("ab%", &like_holder); + auto status = LikeHolder::Make("ab%", &like_holder, regex_op); EXPECT_EQ(status.ok(), true) << status.message(); auto& like = *like_holder; @@ -63,7 +64,7 @@ TEST_F(TestLikeHolder, TestMatchAny) { TEST_F(TestLikeHolder, TestMatchOne) { std::shared_ptr like_holder; - auto status = LikeHolder::Make("ab_", &like_holder); + auto status = LikeHolder::Make("ab_", &like_holder, regex_op); EXPECT_EQ(status.ok(), true) << status.message(); auto& like = *like_holder; @@ -78,7 +79,7 @@ TEST_F(TestLikeHolder, TestMatchOne) { TEST_F(TestLikeHolder, TestPcreSpecial) { std::shared_ptr like_holder; - auto status = LikeHolder::Make(".*ab_", &like_holder); + auto status = LikeHolder::Make(".*ab_", &like_holder, regex_op); EXPECT_EQ(status.ok(), true) << status.message(); auto& like = *like_holder; @@ -97,7 +98,7 @@ TEST_F(TestLikeHolder, TestRegexEscape) { TEST_F(TestLikeHolder, TestDot) { std::shared_ptr like_holder; - auto status = LikeHolder::Make("abc.", &like_holder); + auto status = LikeHolder::Make("abc.", &like_holder, regex_op); EXPECT_EQ(status.ok(), true) << status.message(); auto& like = *like_holder;