Skip to content

Commit

Permalink
Remove unnecessary Make method
Browse files Browse the repository at this point in the history
  • Loading branch information
jvictorhuguenin committed Jun 7, 2021
1 parent c2363b1 commit 97e6e2d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
12 changes: 9 additions & 3 deletions cpp/src/gandiva/like_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ Status LikeHolder::Make(const FunctionNode& node, std::shared_ptr<LikeHolder>* 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<std::string>(literal->holder()), holder, regex_op);
Expand Down Expand Up @@ -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<LikeHolder>(new LikeHolder(pcre_pattern, regex_op));
std::shared_ptr<LikeHolder> lholder;
if (regex_op.case_sensitive()) {
lholder = std::shared_ptr<LikeHolder>(new LikeHolder(pcre_pattern));
} else {
lholder = std::shared_ptr<LikeHolder>(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
2 changes: 1 addition & 1 deletion cpp/src/gandiva/like_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions cpp/src/gandiva/like_holder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<FieldNode>(arrow::field("in", arrow::utf8()));
auto pattern_node =
Expand All @@ -48,7 +49,7 @@ class TestLikeHolder : public ::testing::Test {
TEST_F(TestLikeHolder, TestMatchAny) {
std::shared_ptr<LikeHolder> 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;
Expand All @@ -63,7 +64,7 @@ TEST_F(TestLikeHolder, TestMatchAny) {
TEST_F(TestLikeHolder, TestMatchOne) {
std::shared_ptr<LikeHolder> 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;
Expand All @@ -78,7 +79,7 @@ TEST_F(TestLikeHolder, TestMatchOne) {
TEST_F(TestLikeHolder, TestPcreSpecial) {
std::shared_ptr<LikeHolder> 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;
Expand All @@ -97,7 +98,7 @@ TEST_F(TestLikeHolder, TestRegexEscape) {
TEST_F(TestLikeHolder, TestDot) {
std::shared_ptr<LikeHolder> 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;
Expand Down

0 comments on commit 97e6e2d

Please sign in to comment.