You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/28 10:34:48 UTC

[GitHub] [arrow] ViniciusSouzaRoque commented on a diff in pull request #13656: ARROW-17144: [C++][Gandiva] Add sqrt function

ViniciusSouzaRoque commented on code in PR #13656:
URL: https://github.com/apache/arrow/pull/13656#discussion_r932057583


##########
cpp/src/gandiva/tests/projector_test.cc:
##########
@@ -3384,4 +3384,111 @@ TEST_F(TestProjector, TestMaskDefault) {
   EXPECT_ARROW_ARRAY_EQUALS(exp_mask, outputs.at(0));
 }
 
+TEST_F(TestProjector, TestSqrt) {
+  // input fields
+  auto field1 = field("f1", arrow::int32());
+  auto field2 = field("f2", arrow::int64());
+  auto field3 = field("f3", arrow::float32());
+  auto field4 = field("f4", arrow::float64());
+
+  // schema fields
+  auto schema1 = arrow::schema({field1});
+  auto schema2 = arrow::schema({field2});
+  auto schema3 = arrow::schema({field3});
+  auto schema4 = arrow::schema({field4});
+
+  // output fields
+  auto field5 = field("sqrt_int32", arrow::float64());
+  auto field6 = field("sqrt_int64", arrow::float64());
+  auto field7 = field("sqrt_float32", arrow::float64());
+  auto field8 = field("sqrt_float64", arrow::float64());
+
+  // Build expression
+  auto sqrt_int32 = TreeExprBuilder::MakeExpression("sqrt", {field1}, field5);
+  auto sqrt_int64 = TreeExprBuilder::MakeExpression("sqrt", {field2}, field6);
+  auto sqrt_float32 = TreeExprBuilder::MakeExpression("sqrt", {field3}, field7);
+  auto sqrt_float64 = TreeExprBuilder::MakeExpression("sqrt", {field4}, field8);
+
+  std::shared_ptr<Projector> projector1;
+
+  auto status = Projector::Make(schema1, {sqrt_int32}, TestConfiguration(), &projector1);
+  EXPECT_TRUE(status.ok()) << status.message();
+
+  // Create a row-batch with some sample data
+  int num_records = 4;
+
+  auto array1 = MakeArrowArrayInt32({1, 4, 9, 16}, {true, true, true, true});
+  auto in_batch1 = arrow::RecordBatch::Make(schema1, num_records, {array1});
+
+  auto out_int32 = MakeArrowArrayFloat64({1.0, 2.0, 3.0, 4.0}, {true, true, true, true});
+
+  arrow::ArrayVector outputs1;
+
+  // Evaluate expression
+  status = projector1->Evaluate(*in_batch1, pool_, &outputs1);
+  EXPECT_TRUE(status.ok()) << status.message();
+
+  EXPECT_ARROW_ARRAY_EQUALS(out_int32, outputs1.at(0));
+
+  std::shared_ptr<Projector> projector2;
+
+  status = Projector::Make(schema2, {sqrt_int64}, TestConfiguration(), &projector2);

Review Comment:
   @kou For similar functions where change only type of entries, we join in same test
   For inverse functions too, like encrypt/decrypt tests



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org