| 38 | }; |
| 39 | |
| 40 | TEST_F(TestIfExpr, TestSimple) { |
| 41 | // schema for input fields |
| 42 | auto fielda = field("a", int32()); |
| 43 | auto fieldb = field("b", int32()); |
| 44 | auto schema = arrow::schema({fielda, fieldb}); |
| 45 | |
| 46 | // output fields |
| 47 | auto field_result = field("res", int32()); |
| 48 | |
| 49 | // build expression. |
| 50 | // if (a > b) |
| 51 | // a |
| 52 | // else |
| 53 | // b |
| 54 | auto node_a = TreeExprBuilder::MakeField(fielda); |
| 55 | auto node_b = TreeExprBuilder::MakeField(fieldb); |
| 56 | auto condition = |
| 57 | TreeExprBuilder::MakeFunction("greater_than", {node_a, node_b}, boolean()); |
| 58 | auto if_node = TreeExprBuilder::MakeIf(condition, node_a, node_b, int32()); |
| 59 | |
| 60 | auto expr = TreeExprBuilder::MakeExpression(if_node, field_result); |
| 61 | |
| 62 | // Build a projector for the expressions. |
| 63 | std::shared_ptr<Projector> projector; |
| 64 | auto status = Projector::Make(schema, {expr}, TestConfiguration(), &projector); |
| 65 | EXPECT_TRUE(status.ok()); |
| 66 | |
| 67 | // Create a row-batch with some sample data |
| 68 | int num_records = 4; |
| 69 | auto array0 = MakeArrowArrayInt32({10, 12, -20, 5}, {true, true, true, false}); |
| 70 | auto array1 = MakeArrowArrayInt32({5, 15, 15, 17}, {true, true, true, true}); |
| 71 | |
| 72 | // expected output |
| 73 | auto exp = MakeArrowArrayInt32({10, 15, 15, 17}, {true, true, true, true}); |
| 74 | |
| 75 | // prepare input record batch |
| 76 | auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array0, array1}); |
| 77 | |
| 78 | // Evaluate expression |
| 79 | arrow::ArrayVector outputs; |
| 80 | status = projector->Evaluate(*in_batch, pool_, &outputs); |
| 81 | EXPECT_TRUE(status.ok()); |
| 82 | |
| 83 | // Validate results |
| 84 | EXPECT_ARROW_ARRAY_EQUALS(exp, outputs.at(0)); |
| 85 | } |
| 86 | |
| 87 | TEST_F(TestIfExpr, TestSimpleArithmetic) { |
| 88 | // schema for input fields |
nothing calls this directly
no test coverage detected