Skip to content

Commit 73927fc

Browse files
committed
Add projector test for LPAD string function
1 parent 2c929a9 commit 73927fc

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
@@ -1010,4 +1010,47 @@ TEST_F(TestProjector, TestIfElseOpt) {
10101010
EXPECT_ARROW_ARRAY_EQUALS(exp, outputs.at(0));
10111011
}
10121012

1013+
TEST_F(TestProjector, TestLpad) {
1014+
// schema for input fields
1015+
auto field0 = field("f0", arrow::utf8());
1016+
auto field1 = field("f1", arrow::int32());
1017+
auto field2 = field("f2", arrow::utf8());
1018+
auto schema = arrow::schema({field0, field1, field2});
1019+
1020+
// output fields
1021+
auto field_lpad = field("lpad", arrow::utf8());
1022+
1023+
// Build expression
1024+
auto lpad_expr =
1025+
TreeExprBuilder::MakeExpression("lpad", {field0, field1, field2}, field_lpad);
1026+
1027+
std::shared_ptr<Projector> projector;
1028+
auto status = Projector::Make(schema, {lpad_expr}, TestConfiguration(), &projector);
1029+
EXPECT_TRUE(status.ok()) << status.message();
1030+
1031+
// Create a row-batch with some sample data
1032+
int num_records = 7;
1033+
auto array0 = MakeArrowArrayUtf8({"ab", "a", "ab", "invalid", "valid", "invalid", ""},
1034+
{true, true, true, true, true, true, true});
1035+
auto array1 = MakeArrowArrayInt32({1, 5, 3, 12, 0, 2, 10},
1036+
{true, true, true, true, true, true, true});
1037+
auto array2 = MakeArrowArrayUtf8({"z", "z", "c", "valid", "invalid", "invalid", ""},
1038+
{true, true, true, true, true, true, true});
1039+
// expected output
1040+
auto exp_lpad = MakeArrowArrayUtf8({"a", "zzzza", "cab", "validinvalid", "", "in", ""},
1041+
{true, true, true, true, true, true, true});
1042+
1043+
// prepare input record batch
1044+
auto in_batch = arrow::RecordBatch::Make(schema, num_records,
1045+
{array0, array1, array2});
1046+
1047+
// Evaluate expression
1048+
arrow::ArrayVector outputs;
1049+
status = projector->Evaluate(*in_batch, pool_, &outputs);
1050+
EXPECT_TRUE(status.ok()) << status.message();
1051+
1052+
// Validate results
1053+
EXPECT_ARROW_ARRAY_EQUALS(exp_lpad, outputs.at(0));
1054+
}
1055+
10131056
} // namespace gandiva

0 commit comments

Comments
 (0)