Add integration tests for sha hash functions

This commit is contained in:
Anthony Louis committed 2021-04-09 19:34:23 -03:00
1 parent 5ddcf05697
commit be7ebee19e
1 file changed
+68
+68
View File
@@ -31,6 +31,8 @@ using arrow::boolean;
using arrow::int32;
using arrow::int64;
using arrow::utf8;
using arrow::float64;
using arrow::float32;
class TestHash : public ::testing::Test {
public:
@@ -147,4 +149,70 @@ TEST_F(TestHash, TestBuf) {
}
}
TEST_F(TestHash, TestSha256Simple) {
// schema for input fields
auto field_a = field("a", int32());
auto field_b = field("b", int64());\
auto field_c = field("c", float32());
auto field_d = field("d", float64());
auto schema = arrow::schema({field_a, field_b, field_c, field_d});
// output fields
auto res_0 = field("res0", utf8());
auto res_1 = field("res1", utf8());
auto res_2 = field("res2", utf8());
auto res_3 = field("res3", utf8());
// build expressions.
// hashSHA256(a)
auto node_a = TreeExprBuilder::MakeField(field_a);
auto hashSha256_1 = TreeExprBuilder::MakeFunction("hashSHA256", {node_a}, utf8());
auto expr_0 = TreeExprBuilder::MakeExpression(hashSha256_1, res_0);
auto node_b = TreeExprBuilder::MakeField(field_b);
auto hashSha256_2 = TreeExprBuilder::MakeFunction("hashSHA256", {node_b}, utf8());
auto expr_1 = TreeExprBuilder::MakeExpression(hashSha256_2, res_1);
auto node_c = TreeExprBuilder::MakeField(field_c);
auto hashSha256_3 = TreeExprBuilder::MakeFunction("hashSHA256", {node_c}, utf8());
auto expr_2 = TreeExprBuilder::MakeExpression(hashSha256_3, res_2);
auto node_d = TreeExprBuilder::MakeField(field_d);
auto hashSha256_4 = TreeExprBuilder::MakeFunction("hashSHA256", {node_d}, utf8());
auto expr_3 = TreeExprBuilder::MakeExpression(hashSha256_4, res_3);
// Build a projector for the expressions.
std::shared_ptr<Projector> projector;
auto status =
Projector::Make(schema, {expr_0, expr_1, expr_2, expr_3}, TestConfiguration(), &projector);
EXPECT_TRUE(status.ok()) << status.message();
// Create a row-batch with some sample data
int num_records = 4;
auto validity_array = {false, true, true, true};
auto array_int32 =
MakeArrowArrayInt32({1, 2, 3, 4}, validity_array);
auto array_int64 =
MakeArrowArrayInt64({1, 2, 3, 4}, validity_array);
auto array_float32 =
MakeArrowArrayFloat32({1.0, 2.0, 3.0, 4.0}, validity_array);
auto array_float64 =
MakeArrowArrayFloat64({1.0, 2.0, 3.0, 4.0}, validity_array);
// prepare input record batch
auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array_int32, array_int64,
array_float32, array_float64});
// Evaluate expression
arrow::ArrayVector outputs;
status = projector->Evaluate(*in_batch, pool_, &outputs);
EXPECT_TRUE(status.ok());
}
} // namespace gandiva