| 43 | }; |
| 44 | |
| 45 | TEST_F(TestHash, TestSimple) { |
| 46 | // schema for input fields |
| 47 | auto field_a = field("a", int32()); |
| 48 | auto schema = arrow::schema({field_a}); |
| 49 | |
| 50 | // output fields |
| 51 | auto res_0 = field("res0", int32()); |
| 52 | auto res_1 = field("res1", int64()); |
| 53 | |
| 54 | // build expression. |
| 55 | // hash32(a, 10) |
| 56 | // hash64(a) |
| 57 | auto node_a = TreeExprBuilder::MakeField(field_a); |
| 58 | auto literal_10 = TreeExprBuilder::MakeLiteral((int32_t)10); |
| 59 | auto hash32 = TreeExprBuilder::MakeFunction("hash32", {node_a, literal_10}, int32()); |
| 60 | auto hash64 = TreeExprBuilder::MakeFunction("hash64", {node_a}, int64()); |
| 61 | auto expr_0 = TreeExprBuilder::MakeExpression(hash32, res_0); |
| 62 | auto expr_1 = TreeExprBuilder::MakeExpression(hash64, res_1); |
| 63 | |
| 64 | // Build a projector for the expression. |
| 65 | std::shared_ptr<Projector> projector; |
| 66 | auto status = |
| 67 | Projector::Make(schema, {expr_0, expr_1}, TestConfiguration(), &projector); |
| 68 | EXPECT_TRUE(status.ok()) << status.message(); |
| 69 | |
| 70 | // Create a row-batch with some sample data |
| 71 | int num_records = 4; |
| 72 | auto array_a = MakeArrowArrayInt32({1, 2, 3, 4}, {false, true, true, true}); |
| 73 | |
| 74 | // prepare input record batch |
| 75 | auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array_a}); |
| 76 | |
| 77 | // Evaluate expression |
| 78 | arrow::ArrayVector outputs; |
| 79 | status = projector->Evaluate(*in_batch, pool_, &outputs); |
| 80 | EXPECT_TRUE(status.ok()); |
| 81 | |
| 82 | // Validate results |
| 83 | auto int32_arr = std::dynamic_pointer_cast<arrow::Int32Array>(outputs.at(0)); |
| 84 | EXPECT_EQ(int32_arr->null_count(), 0); |
| 85 | EXPECT_EQ(int32_arr->Value(0), 10); |
| 86 | for (int i = 1; i < num_records; ++i) { |
| 87 | EXPECT_NE(int32_arr->Value(i), int32_arr->Value(i - 1)); |
| 88 | } |
| 89 | |
| 90 | auto int64_arr = std::dynamic_pointer_cast<arrow::Int64Array>(outputs.at(1)); |
| 91 | EXPECT_EQ(int64_arr->null_count(), 0); |
| 92 | EXPECT_EQ(int64_arr->Value(0), 0); |
| 93 | for (int i = 1; i < num_records; ++i) { |
| 94 | EXPECT_NE(int64_arr->Value(i), int64_arr->Value(i - 1)); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | TEST_F(TestHash, TestBuf) { |
| 99 | // schema for input fields |
nothing calls this directly
no test coverage detected