niyue commented on code in PR #38632:
URL: https://github.com/apache/arrow/pull/38632#discussion_r1386048070
##########
cpp/src/gandiva/tests/projector_test.cc:
##########
@@ -3608,4 +3608,80 @@ TEST_F(TestProjector, TestExtendedFunctions) {
EXPECT_ARROW_ARRAY_EQUALS(out, outs.at(0));
}
+TEST_F(TestProjector, TestExtendedCInterfaceFunctions) {
+ auto in_field = field("in", arrow::int32());
+ auto schema = arrow::schema({in_field});
+ auto out_field = field("out", arrow::int64());
+ auto multiply =
+ TreeExprBuilder::MakeExpression("multiply_by_three", {in_field},
out_field);
+
+ std::shared_ptr<Projector> projector;
+ auto external_registry = std::make_shared<FunctionRegistry>();
+ auto config_with_func_registry =
+ TestConfigWithStubFunction(std::move(external_registry));
+ ARROW_EXPECT_OK(
+ Projector::Make(schema, {multiply}, config_with_func_registry,
&projector));
+
+ int num_records = 4;
+ auto array = MakeArrowArrayInt32({1, 2, 3, 4}, {true, true, true, true});
+ auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array});
+ auto out = MakeArrowArrayInt64({3, 6, 9, 12}, {true, true, true, true});
+
+ arrow::ArrayVector outs;
+ ARROW_EXPECT_OK(projector->Evaluate(*in_batch, pool_, &outs));
+ EXPECT_ARROW_ARRAY_EQUALS(out, outs.at(0));
+}
+
+TEST_F(TestProjector, TestExtendedCInterfaceFunctionsWithFunctionHolder) {
+ auto multiple = TreeExprBuilder::MakeLiteral(5);
+ auto in_field = field("in", arrow::int32());
+ auto schema = arrow::schema({in_field});
+ auto out_field = field("out", arrow::int64());
+
+ auto in_node = TreeExprBuilder::MakeField(in_field);
+ auto multiply_by_n_func =
+ TreeExprBuilder::MakeFunction("multiply_by_n", {in_node, multiple},
arrow::int64());
+ auto multiply = TreeExprBuilder::MakeExpression(multiply_by_n_func,
out_field);
+
+ std::shared_ptr<Projector> projector;
+ auto external_registry = std::make_shared<FunctionRegistry>();
+ auto config_with_func_registry =
+ TestConfigWithHolderFunction(std::move(external_registry));
+ ARROW_EXPECT_OK(
+ Projector::Make(schema, {multiply}, config_with_func_registry,
&projector));
+
+ int num_records = 4;
+ auto array = MakeArrowArrayInt32({1, 2, 3, 4}, {true, true, true, true});
+ auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array});
+ auto out = MakeArrowArrayInt64({5, 10, 15, 20}, {true, true, true, true});
+
+ arrow::ArrayVector outs;
+ ARROW_EXPECT_OK(projector->Evaluate(*in_batch, pool_, &outs));
+ EXPECT_ARROW_ARRAY_EQUALS(out, outs.at(0));
+}
+
+TEST_F(TestProjector, TestExtendedCInterfaceFunctionThatNeedsContext) {
Review Comment:
This test case demonstrates registering an external C interface function
that uses context.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]