Skip to content

Commit b6b63e9

Browse files
committed
Add projector test for RPAD string function
1 parent dc72148 commit b6b63e9

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

cpp/src/gandiva/tests/projector_test.cc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,4 +1053,47 @@ TEST_F(TestProjector, TestLpad) {
10531053
EXPECT_ARROW_ARRAY_EQUALS(exp_lpad, outputs.at(0));
10541054
}
10551055

1056+
TEST_F(TestProjector, TestRpad) {
1057+
// schema for input fields
1058+
auto field0 = field("f0", arrow::utf8());
1059+
auto field1 = field("f1", arrow::int32());
1060+
auto field2 = field("f2", arrow::utf8());
1061+
auto schema = arrow::schema({field0, field1, field2});
1062+
1063+
// output fields
1064+
auto field_rpad = field("rpad", arrow::utf8());
1065+
1066+
// Build expression
1067+
auto rpad_expr =
1068+
TreeExprBuilder::MakeExpression("rpad", {field0, field1, field2}, field_rpad);
1069+
1070+
std::shared_ptr<Projector> projector;
1071+
auto status = Projector::Make(schema, {rpad_expr}, TestConfiguration(), &projector);
1072+
EXPECT_TRUE(status.ok()) << status.message();
1073+
1074+
// Create a row-batch with some sample data
1075+
int num_records = 7;
1076+
auto array0 = MakeArrowArrayUtf8({"ab", "a", "ab", "invalid", "valid", "invalid", ""},
1077+
{true, true, true, true, true, true, true});
1078+
auto array1 = MakeArrowArrayInt32({1, 5, 3, 12, 0, 2, 10},
1079+
{true, true, true, true, true, true, true});
1080+
auto array2 = MakeArrowArrayUtf8({"z", "z", "c", "valid", "invalid", "invalid", ""},
1081+
{true, true, true, true, true, true, true});
1082+
// expected output
1083+
auto exp_rpad = MakeArrowArrayUtf8({"a", "azzzz", "abc", "invalidvalid", "", "in", ""},
1084+
{true, true, true, true, true, true, true});
1085+
1086+
// prepare input record batch
1087+
auto in_batch = arrow::RecordBatch::Make(schema, num_records,
1088+
{array0, array1, array2});
1089+
1090+
// Evaluate expression
1091+
arrow::ArrayVector outputs;
1092+
status = projector->Evaluate(*in_batch, pool_, &outputs);
1093+
EXPECT_TRUE(status.ok()) << status.message();
1094+
1095+
// Validate results
1096+
EXPECT_ARROW_ARRAY_EQUALS(exp_rpad, outputs.at(0));
1097+
}
1098+
10561099
} // namespace gandiva

0 commit comments

Comments
 (0)