| 39 | }; |
| 40 | |
| 41 | TEST_F(TestBinary, TestSimple) { |
| 42 | // schema for input fields |
| 43 | auto field_a = field("a", binary()); |
| 44 | auto field_b = field("b", binary()); |
| 45 | auto schema = arrow::schema({field_a, field_b}); |
| 46 | |
| 47 | // output fields |
| 48 | auto res = field("res", int32()); |
| 49 | |
| 50 | // build expressions. |
| 51 | // a > b ? octet_length(a) : octet_length(b) |
| 52 | auto node_a = TreeExprBuilder::MakeField(field_a); |
| 53 | auto node_b = TreeExprBuilder::MakeField(field_b); |
| 54 | auto octet_len_a = TreeExprBuilder::MakeFunction("octet_length", {node_a}, int32()); |
| 55 | auto octet_len_b = TreeExprBuilder::MakeFunction("octet_length", {node_b}, int32()); |
| 56 | |
| 57 | auto is_greater = |
| 58 | TreeExprBuilder::MakeFunction("greater_than", {node_a, node_b}, boolean()); |
| 59 | auto if_greater = |
| 60 | TreeExprBuilder::MakeIf(is_greater, octet_len_a, octet_len_b, int32()); |
| 61 | auto expr = TreeExprBuilder::MakeExpression(if_greater, res); |
| 62 | |
| 63 | // Build a projector for the expressions. |
| 64 | std::shared_ptr<Projector> projector; |
| 65 | auto status = Projector::Make(schema, {expr}, TestConfiguration(), &projector); |
| 66 | EXPECT_TRUE(status.ok()) << status.message(); |
| 67 | |
| 68 | // Create a row-batch with some sample data |
| 69 | int num_records = 4; |
| 70 | auto array_a = |
| 71 | MakeArrowArrayBinary({"foo", "hello", "hi", "bye"}, {true, true, true, false}); |
| 72 | auto array_b = |
| 73 | MakeArrowArrayBinary({"fo", "hellos", "hi", "bye"}, {true, true, true, true}); |
| 74 | |
| 75 | // expected output |
| 76 | auto exp = MakeArrowArrayInt32({3, 6, 2, 3}, {true, true, true, true}); |
| 77 | |
| 78 | // prepare input record batch |
| 79 | auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array_a, array_b}); |
| 80 | |
| 81 | // Evaluate expression |
| 82 | arrow::ArrayVector outputs; |
| 83 | status = projector->Evaluate(*in_batch, pool_, &outputs); |
| 84 | EXPECT_TRUE(status.ok()); |
| 85 | |
| 86 | // Validate results |
| 87 | EXPECT_ARROW_ARRAY_EQUALS(exp, outputs.at(0)); |
| 88 | } |
| 89 | |
| 90 | TEST_F(TestBinary, TestIfElse) { |
| 91 | // schema for input fields |
nothing calls this directly
no test coverage detected