Skip to content

Commit

Permalink
apacheGH-40727: 'ilike' function does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
lriggs committed Mar 22, 2024
1 parent d34de39 commit 1db8b45
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions cpp/src/gandiva/function_holder_maker_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ arrow::Result<FunctionHolderPtr> FunctionHolderMakerRegistry::Make(
FunctionHolderMakerRegistry::MakerMap FunctionHolderMakerRegistry::DefaultHolderMakers() {
static const MakerMap maker_map = {
{"like", HolderMaker<LikeHolder>},
{"ilike", HolderMaker<LikeHolder>},
{"to_date", HolderMaker<ToDateHolder>},
{"random", HolderMaker<RandomGeneratorHolder>},
{"rand", HolderMaker<RandomGeneratorHolder>},
Expand Down
41 changes: 41 additions & 0 deletions cpp/src/gandiva/tests/utf8_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,47 @@ TEST_F(TestUtf8, TestLike) {
EXPECT_ARROW_ARRAY_EQUALS(exp, outputs.at(0));
}

TEST_F(TestUtf8, TestIlike) {
// schema for input fields
auto field_a = field("a", utf8());
auto schema = arrow::schema({field_a});

// output fields
auto res = field("res", boolean());

// build expressions.
// like(literal(s), a)

auto node_a = TreeExprBuilder::MakeField(field_a);
auto literal_s = TreeExprBuilder::MakeStringLiteral("%spark%");
auto is_like = TreeExprBuilder::MakeFunction("ilike", {node_a, literal_s}, boolean());
auto expr = TreeExprBuilder::MakeExpression(is_like, res);

// Build a projector for the expressions.
std::shared_ptr<Projector> projector;
auto status = Projector::Make(schema, {expr}, TestConfiguration(), &projector);
EXPECT_TRUE(status.ok()) << status.message();

// Create a row-batch with some sample data
int num_records = 4;
auto array_a = MakeArrowArrayUtf8({"park", "sparkle", "bright spark and fire", "spark"},
{true, true, true, true});

// expected output
auto exp = MakeArrowArrayBool({false, true, true, true}, {true, true, true, true});

// prepare input record batch
auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array_a});

// Evaluate expression
arrow::ArrayVector outputs;
status = projector->Evaluate(*in_batch, pool_, &outputs);
EXPECT_TRUE(status.ok()) << status.message();

// Validate results
EXPECT_ARROW_ARRAY_EQUALS(exp, outputs.at(0));
}

TEST_F(TestUtf8, TestLikeWithEscape) {
// schema for input fields
auto field_a = field("a", utf8());
Expand Down

0 comments on commit 1db8b45

Please sign in to comment.