| 37 | }; |
| 38 | |
| 39 | TEST_F(TestBooleanExpr, SimpleAnd) { |
| 40 | // schema for input fields |
| 41 | auto fielda = field("a", int32()); |
| 42 | auto fieldb = field("b", int32()); |
| 43 | auto schema = arrow::schema({fielda, fieldb}); |
| 44 | |
| 45 | // output fields |
| 46 | auto field_result = field("res", boolean()); |
| 47 | |
| 48 | // build expression. |
| 49 | // (a > 0) && (b > 0) |
| 50 | auto node_a = TreeExprBuilder::MakeField(fielda); |
| 51 | auto node_b = TreeExprBuilder::MakeField(fieldb); |
| 52 | auto literal_0 = TreeExprBuilder::MakeLiteral((int32_t)0); |
| 53 | auto a_gt_0 = |
| 54 | TreeExprBuilder::MakeFunction("greater_than", {node_a, literal_0}, boolean()); |
| 55 | auto b_gt_0 = |
| 56 | TreeExprBuilder::MakeFunction("greater_than", {node_b, literal_0}, boolean()); |
| 57 | |
| 58 | auto node_and = TreeExprBuilder::MakeAnd({a_gt_0, b_gt_0}); |
| 59 | auto expr = TreeExprBuilder::MakeExpression(node_and, field_result); |
| 60 | |
| 61 | // Build a projector for the expressions. |
| 62 | std::shared_ptr<Projector> projector; |
| 63 | auto status = Projector::Make(schema, {expr}, TestConfiguration(), &projector); |
| 64 | EXPECT_TRUE(status.ok()); |
| 65 | |
| 66 | // FALSE_VALID && ? => FALSE_VALID |
| 67 | int num_records = 4; |
| 68 | auto arraya = MakeArrowArrayInt32({-2, -2, -2, -2}, {true, true, true, true}); |
| 69 | auto arrayb = MakeArrowArrayInt32({-2, -2, 2, 2}, {true, false, true, false}); |
| 70 | auto exp = MakeArrowArrayBool({false, false, false, false}, {true, true, true, true}); |
| 71 | auto in_batch = arrow::RecordBatch::Make(schema, num_records, {arraya, arrayb}); |
| 72 | |
| 73 | arrow::ArrayVector outputs; |
| 74 | status = projector->Evaluate(*in_batch, pool_, &outputs); |
| 75 | EXPECT_TRUE(status.ok()); |
| 76 | EXPECT_ARROW_ARRAY_EQUALS(exp, outputs.at(0)); |
| 77 | |
| 78 | // FALSE_INVALID && ? |
| 79 | num_records = 4; |
| 80 | arraya = MakeArrowArrayInt32({-2, -2, -2, -2}, {false, false, false, false}); |
| 81 | arrayb = MakeArrowArrayInt32({-2, -2, 2, 2}, {true, false, true, false}); |
| 82 | exp = MakeArrowArrayBool({false, false, false, false}, {true, false, false, false}); |
| 83 | in_batch = arrow::RecordBatch::Make(schema, num_records, {arraya, arrayb}); |
| 84 | outputs.clear(); |
| 85 | status = projector->Evaluate(*in_batch, pool_, &outputs); |
| 86 | EXPECT_TRUE(status.ok()); |
| 87 | EXPECT_ARROW_ARRAY_EQUALS(exp, outputs.at(0)); |
| 88 | |
| 89 | // TRUE_VALID && ? |
| 90 | num_records = 4; |
| 91 | arraya = MakeArrowArrayInt32({2, 2, 2, 2}, {true, true, true, true}); |
| 92 | arrayb = MakeArrowArrayInt32({-2, -2, 2, 2}, {true, false, true, false}); |
| 93 | exp = MakeArrowArrayBool({false, false, true, false}, {true, false, true, false}); |
| 94 | in_batch = arrow::RecordBatch::Make(schema, num_records, {arraya, arrayb}); |
| 95 | outputs.clear(); |
| 96 | status = projector->Evaluate(*in_batch, pool_, &outputs); |
nothing calls this directly
no test coverage detected