Skip to content

Commit

Permalink
Disable TryOptimize for ilike
Browse files Browse the repository at this point in the history
  • Loading branch information
jvictorhuguenin committed Jun 7, 2021
1 parent a484149 commit c2363b1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 34 deletions.
2 changes: 1 addition & 1 deletion cpp/src/gandiva/expr_decomposer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Status ExprDecomposer::Visit(const FieldNode& node) {
// eg. replacing 'like' with 'starts_with' can save function calls at evaluation
// time.
const FunctionNode ExprDecomposer::TryOptimize(const FunctionNode& node) {
if (node.descriptor()->name() == "like" || node.descriptor()->name() == "ilike") {
if (node.descriptor()->name() == "like") {
return LikeHolder::TryOptimize(node);
} else {
return node;
Expand Down
33 changes: 0 additions & 33 deletions cpp/src/gandiva/like_holder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,37 +277,4 @@ TEST_F(TestILikeHolder, TestDot) {
EXPECT_FALSE(like("abcd"));
}

TEST_F(TestILikeHolder, TestOptimise) {
// optimise for 'starts_with'
auto fnode = LikeHolder::TryOptimize(BuildILike("xy 123z%"));
EXPECT_EQ(fnode.descriptor()->name(), "starts_with");
EXPECT_EQ(fnode.ToString(), "bool starts_with((string) in, (const string) xy 123z)");

// optimise for 'ends_with'
fnode = LikeHolder::TryOptimize(BuildILike("%xyz"));
EXPECT_EQ(fnode.descriptor()->name(), "ends_with");
EXPECT_EQ(fnode.ToString(), "bool ends_with((string) in, (const string) xyz)");

// optimise for 'is_substr'
fnode = LikeHolder::TryOptimize(BuildILike("%abc%"));
EXPECT_EQ(fnode.descriptor()->name(), "is_substr");
EXPECT_EQ(fnode.ToString(), "bool is_substr((string) in, (const string) abc)");

// no optimisation for others.
fnode = LikeHolder::TryOptimize(BuildILike("xyz_"));
EXPECT_EQ(fnode.descriptor()->name(), "ilike");

fnode = LikeHolder::TryOptimize(BuildILike("_xyz"));
EXPECT_EQ(fnode.descriptor()->name(), "ilike");

fnode = LikeHolder::TryOptimize(BuildILike("_xyz_"));
EXPECT_EQ(fnode.descriptor()->name(), "ilike");

fnode = LikeHolder::TryOptimize(BuildILike("%xyz_"));
EXPECT_EQ(fnode.descriptor()->name(), "ilike");

fnode = LikeHolder::TryOptimize(BuildILike("x_yz%"));
EXPECT_EQ(fnode.descriptor()->name(), "ilike");
}

} // namespace gandiva

0 comments on commit c2363b1

Please sign in to comment.