kou commented on code in PR #13643: URL: https://github.com/apache/arrow/pull/13643#discussion_r929277383
########## cpp/src/gandiva/tests/projector_test.cc: ########## @@ -3384,4 +3384,50 @@ TEST_F(TestProjector, TestMaskDefault) { EXPECT_ARROW_ARRAY_EQUALS(exp_mask, outputs.at(0)); } +TEST_F(TestProjector, TestRepeatStr) { + // schema for input fields Review Comment: How about sharing existing test scenario for `repeat` instead of creating another test scenario like the following because `repeatStr` is an alias of `repeat`? ```diff diff --git a/cpp/src/gandiva/tests/projector_test.cc b/cpp/src/gandiva/tests/projector_test.cc index 65597b38f0..5468055c74 100644 --- a/cpp/src/gandiva/tests/projector_test.cc +++ b/cpp/src/gandiva/tests/projector_test.cc @@ -48,6 +48,44 @@ class TestProjector : public ::testing::Test { protected: arrow::MemoryPool* pool_; + + void ExpectRepeat(const std::string& name) { + // schema for input fields + auto field0 = field("f0", arrow::utf8()); + auto field1 = field("f1", arrow::int32()); + auto schema = arrow::schema({field0, field1}); + + // output fields + auto field_repeat = field(name, arrow::utf8()); + + // Build expression + auto repeat_expr = + TreeExprBuilder::MakeExpression(name, {field0, field1}, field_repeat); + + std::shared_ptr<Projector> projector; + auto status = Projector::Make(schema, {repeat_expr}, TestConfiguration(), &projector); + EXPECT_TRUE(status.ok()) << status.message(); + + // Create a row-batch with some sample data + int num_records = 5; + auto array0 = + MakeArrowArrayUtf8({"ab", "a", "car", "valid", ""}, {true, true, true, true, true}); + auto array1 = MakeArrowArrayInt32({2, 1, 3, 2, 10}, {true, true, true, true, true}); + // expected output + auto exp_repeat = MakeArrowArrayUtf8({"abab", "a", "carcarcar", "validvalid", ""}, + {true, true, true, true, true}); + + // prepare input record batch + auto in = arrow::RecordBatch::Make(schema, num_records, {array0, array1}); + + // Evaluate expression + arrow::ArrayVector outputs; + status = projector->Evaluate(*in, pool_, &outputs); + EXPECT_TRUE(status.ok()) << status.message(); + + // Validate results + EXPECT_ARROW_ARRAY_EQUALS(exp_repeat, outputs.at(0)); + } }; TEST_F(TestProjector, TestProjectCache) { @@ -2031,41 +2069,11 @@ TEST_F(TestProjector, TestIfElseOpt) { } TEST_F(TestProjector, TestRepeat) { - // schema for input fields - auto field0 = field("f0", arrow::utf8()); - auto field1 = field("f1", arrow::int32()); - auto schema = arrow::schema({field0, field1}); - - // output fields - auto field_repeat = field("repeat", arrow::utf8()); - - // Build expression - auto repeat_expr = - TreeExprBuilder::MakeExpression("repeat", {field0, field1}, field_repeat); - - std::shared_ptr<Projector> projector; - auto status = Projector::Make(schema, {repeat_expr}, TestConfiguration(), &projector); - EXPECT_TRUE(status.ok()) << status.message(); - - // Create a row-batch with some sample data - int num_records = 5; - auto array0 = - MakeArrowArrayUtf8({"ab", "a", "car", "valid", ""}, {true, true, true, true, true}); - auto array1 = MakeArrowArrayInt32({2, 1, 3, 2, 10}, {true, true, true, true, true}); - // expected output - auto exp_repeat = MakeArrowArrayUtf8({"abab", "a", "carcarcar", "validvalid", ""}, - {true, true, true, true, true}); - - // prepare input record batch - auto in = arrow::RecordBatch::Make(schema, num_records, {array0, array1}); - - // Evaluate expression - arrow::ArrayVector outputs; - status = projector->Evaluate(*in, pool_, &outputs); - EXPECT_TRUE(status.ok()) << status.message(); + ExpectRepeat("repeat"); +} - // Validate results - EXPECT_ARROW_ARRAY_EQUALS(exp_repeat, outputs.at(0)); +TEST_F(TestProjector, TestRepeatStr) { + ExpectRepeat("repeatStr"); } TEST_F(TestProjector, TestLpad) { ``` -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org