diff --git a/cpp/examples/arrow/CMakeLists.txt b/cpp/examples/arrow/CMakeLists.txt index e11b3bd0ab2..229373665d5 100644 --- a/cpp/examples/arrow/CMakeLists.txt +++ b/cpp/examples/arrow/CMakeLists.txt @@ -133,4 +133,7 @@ if(ARROW_PARQUET AND ARROW_DATASET) add_arrow_example(join_example EXTRA_LINK_LIBS ${DATASET_EXAMPLES_LINK_LIBS}) add_dependencies(join-example parquet) + + add_arrow_example(udf_example) + endif() diff --git a/cpp/examples/arrow/compute_register_example.cc b/cpp/examples/arrow/compute_register_example.cc index 0f6165a0646..f089b910ec4 100644 --- a/cpp/examples/arrow/compute_register_example.cc +++ b/cpp/examples/arrow/compute_register_example.cc @@ -126,7 +126,7 @@ const cp::FunctionDoc func_doc{ int main(int argc, char** argv) { const std::string name = "compute_register_example"; - auto func = std::make_shared(name, cp::Arity::Unary(), &func_doc); + auto func = std::make_shared(name, cp::Arity::Unary(), func_doc); cp::ScalarKernel kernel({cp::InputType::Array(arrow::int64())}, arrow::int64(), ExampleFunctionImpl); kernel.mem_allocation = cp::MemAllocation::NO_PREALLOCATE; diff --git a/cpp/examples/arrow/udf_example.cc b/cpp/examples/arrow/udf_example.cc new file mode 100644 index 00000000000..f45e2c644d0 --- /dev/null +++ b/cpp/examples/arrow/udf_example.cc @@ -0,0 +1,103 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +// Demonstrate registering a user-defined Arrow compute function outside of the Arrow +// source tree + +namespace cp = ::arrow::compute; + +#define ABORT_ON_FAILURE(expr) \ + do { \ + arrow::Status status_ = (expr); \ + if (!status_.ok()) { \ + std::cerr << status_.message() << std::endl; \ + abort(); \ + } \ + } while (0); + +template ::value | + arrow::is_boolean_type::value | + arrow::is_temporal_type::value>::type> +arrow::Result> GetArrayDataSample( + const std::vector& values) { + using ArrowBuilderType = typename arrow::TypeTraits::BuilderType; + ArrowBuilderType builder; + ARROW_RETURN_NOT_OK(builder.Reserve(values.size())); + ARROW_RETURN_NOT_OK(builder.AppendValues(values)); + return builder.Finish(); +} + +const cp::FunctionDoc func_doc{ + "User-defined-function usage to demonstrate registering an out-of-tree function", + "returns x + y + z", + {"x", "y", "z"}, + "UDFOptions"}; + +arrow::Status SampleFunction(cp::KernelContext* ctx, const cp::ExecBatch& batch, + arrow::Datum* out) { + // temp = x + y; return temp + z + ARROW_ASSIGN_OR_RAISE(auto temp, cp::CallFunction("add", {batch[0], batch[1]})); + return cp::CallFunction("add", {temp, batch[2]}).Value(out); +} + +arrow::Status Execute() { + const std::string name = "add_three"; + auto func = std::make_shared(name, cp::Arity::Ternary(), func_doc); + cp::ScalarKernel kernel( + {cp::InputType::Array(arrow::int64()), cp::InputType::Array(arrow::int64()), + cp::InputType::Array(arrow::int64())}, + arrow::int64(), SampleFunction); + + kernel.mem_allocation = cp::MemAllocation::NO_PREALLOCATE; + kernel.null_handling = cp::NullHandling::COMPUTED_NO_PREALLOCATE; + + ARROW_RETURN_NOT_OK(func->AddKernel(std::move(kernel))); + + auto registry = cp::GetFunctionRegistry(); + ARROW_RETURN_NOT_OK(registry->AddFunction(std::move(func))); + + ARROW_ASSIGN_OR_RAISE(auto x, GetArrayDataSample({1, 2, 3})); + ARROW_ASSIGN_OR_RAISE(auto y, GetArrayDataSample({4, 5, 6})); + ARROW_ASSIGN_OR_RAISE(auto z, GetArrayDataSample({7, 8, 9})); + + ARROW_ASSIGN_OR_RAISE(auto res, cp::CallFunction(name, {x, y, z})); + auto res_array = res.make_array(); + std::cout << "Result" << std::endl; + std::cout << res_array->ToString() << std::endl; + return arrow::Status::OK(); +} + +int main(int argc, char** argv) { + auto status = Execute(); + if (!status.ok()) { + std::cerr << "Error occurred : " << status.message() << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/cpp/src/arrow/compute/cast.cc b/cpp/src/arrow/compute/cast.cc index 4de68ba8d90..bd49041b4f3 100644 --- a/cpp/src/arrow/compute/cast.cc +++ b/cpp/src/arrow/compute/cast.cc @@ -95,7 +95,7 @@ const FunctionDoc cast_doc{"Cast values to another data type", // to the standard SQL CAST(expr AS target_type) class CastMetaFunction : public MetaFunction { public: - CastMetaFunction() : MetaFunction("cast", Arity::Unary(), &cast_doc) {} + CastMetaFunction() : MetaFunction("cast", Arity::Unary(), cast_doc) {} Result ValidateOptions(const FunctionOptions* options) const { auto cast_options = static_cast(options); @@ -153,7 +153,7 @@ CastOptions::CastOptions(bool safe) constexpr char CastOptions::kTypeName[]; CastFunction::CastFunction(std::string name, Type::type out_type_id) - : ScalarFunction(std::move(name), Arity::Unary(), /*doc=*/nullptr), + : ScalarFunction(std::move(name), Arity::Unary(), FunctionDoc::Empty()), out_type_id_(out_type_id) {} Status CastFunction::AddKernel(Type::type in_type_id, ScalarKernel kernel) { diff --git a/cpp/src/arrow/compute/exec_test.cc b/cpp/src/arrow/compute/exec_test.cc index 198cb84ff5e..b00bcb319c3 100644 --- a/cpp/src/arrow/compute/exec_test.cc +++ b/cpp/src/arrow/compute/exec_test.cc @@ -681,8 +681,8 @@ class TestCallScalarFunction : public TestComputeInternals { // This function simply copies memory from the input argument into the // (preallocated) output - auto func = - std::make_shared("test_copy", Arity::Unary(), /*doc=*/nullptr); + auto func = std::make_shared("test_copy", Arity::Unary(), + /*doc=*/FunctionDoc::Empty()); // Add a few kernels. Our implementation only accepts arrays ASSERT_OK(func->AddKernel({InputType::Array(uint8())}, uint8(), ExecCopy)); @@ -691,8 +691,8 @@ class TestCallScalarFunction : public TestComputeInternals { ASSERT_OK(registry->AddFunction(func)); // A version which doesn't want the executor to call PropagateNulls - auto func2 = std::make_shared("test_copy_computed_bitmap", - Arity::Unary(), /*doc=*/nullptr); + auto func2 = std::make_shared( + "test_copy_computed_bitmap", Arity::Unary(), /*doc=*/FunctionDoc::Empty()); ScalarKernel kernel({InputType::Array(uint8())}, uint8(), ExecComputedBitmap); kernel.null_handling = NullHandling::COMPUTED_PREALLOCATE; ASSERT_OK(func2->AddKernel(kernel)); @@ -705,9 +705,9 @@ class TestCallScalarFunction : public TestComputeInternals { // A function that allocates its own output memory. We have cases for both // non-preallocated data and non-preallocated validity bitmap auto f1 = std::make_shared("test_nopre_data", Arity::Unary(), - /*doc=*/nullptr); - auto f2 = std::make_shared("test_nopre_validity_or_data", - Arity::Unary(), /*doc=*/nullptr); + /*doc=*/FunctionDoc::Empty()); + auto f2 = std::make_shared( + "test_nopre_validity_or_data", Arity::Unary(), /*doc=*/FunctionDoc::Empty()); ScalarKernel kernel({InputType::Array(uint8())}, uint8(), ExecNoPreallocatedData); kernel.mem_allocation = MemAllocation::NO_PREALLOCATE; @@ -727,7 +727,7 @@ class TestCallScalarFunction : public TestComputeInternals { // This function's behavior depends on a static parameter that is made // available to the kernel's execution function through its Options object auto func = std::make_shared("test_stateful", Arity::Unary(), - /*doc=*/nullptr); + /*doc=*/FunctionDoc::Empty()); ScalarKernel kernel({InputType::Array(int32())}, int32(), ExecStateful, InitStateful); ASSERT_OK(func->AddKernel(kernel)); @@ -738,7 +738,7 @@ class TestCallScalarFunction : public TestComputeInternals { auto registry = GetFunctionRegistry(); auto func = std::make_shared("test_scalar_add_int32", Arity::Binary(), - /*doc=*/nullptr); + /*doc=*/FunctionDoc::Empty()); ASSERT_OK(func->AddKernel({InputType::Scalar(int32()), InputType::Scalar(int32())}, int32(), ExecAddInt32)); ASSERT_OK(registry->AddFunction(func)); diff --git a/cpp/src/arrow/compute/function.cc b/cpp/src/arrow/compute/function.cc index 1a7f36862dd..f1b3fcbccf4 100644 --- a/cpp/src/arrow/compute/function.cc +++ b/cpp/src/arrow/compute/function.cc @@ -290,9 +290,9 @@ Status ValidateFunctionDescription(const std::string& s) { } // namespace Status Function::Validate() const { - if (!doc_->summary.empty()) { + if (!doc_.summary.empty()) { // Documentation given, check its contents - int arg_count = static_cast(doc_->arg_names.size()); + int arg_count = static_cast(doc_.arg_names.size()); // Some varargs functions allow 0 vararg, others expect at least 1, // hence the two possible values below. bool arg_count_match = (arg_count == arity_.num_args) || @@ -302,9 +302,9 @@ Status Function::Validate() const { "In function '", name_, "': ", "number of argument names for function documentation != function arity"); } - Status st = ValidateFunctionSummary(doc_->summary); + Status st = ValidateFunctionSummary(doc_.summary); if (st.ok()) { - st &= ValidateFunctionDescription(doc_->description); + st &= ValidateFunctionDescription(doc_.description); } if (!st.ok()) { return st.WithMessage("In function '", name_, "': ", st.message()); diff --git a/cpp/src/arrow/compute/function.h b/cpp/src/arrow/compute/function.h index 1273ab09c4f..face491690f 100644 --- a/cpp/src/arrow/compute/function.h +++ b/cpp/src/arrow/compute/function.h @@ -205,7 +205,7 @@ class ARROW_EXPORT Function { const Arity& arity() const { return arity_; } /// \brief Return the function documentation - const FunctionDoc& doc() const { return *doc_; } + const FunctionDoc& doc() const { return doc_; } /// \brief Returns the number of registered kernels for this function. virtual int num_kernels() const = 0; @@ -244,12 +244,12 @@ class ARROW_EXPORT Function { virtual Status Validate() const; protected: - Function(std::string name, Function::Kind kind, const Arity& arity, - const FunctionDoc* doc, const FunctionOptions* default_options) + Function(std::string name, Function::Kind kind, const Arity& arity, FunctionDoc doc, + const FunctionOptions* default_options) : name_(std::move(name)), kind_(kind), arity_(arity), - doc_(doc ? doc : &FunctionDoc::Empty()), + doc_(std::move(doc)), default_options_(default_options) {} Status CheckArity(const std::vector&) const; @@ -258,7 +258,7 @@ class ARROW_EXPORT Function { std::string name_; Function::Kind kind_; Arity arity_; - const FunctionDoc* doc_; + const FunctionDoc doc_; const FunctionOptions* default_options_ = NULLPTR; }; @@ -279,9 +279,9 @@ class FunctionImpl : public Function { int num_kernels() const override { return static_cast(kernels_.size()); } protected: - FunctionImpl(std::string name, Function::Kind kind, const Arity& arity, - const FunctionDoc* doc, const FunctionOptions* default_options) - : Function(std::move(name), kind, arity, doc, default_options) {} + FunctionImpl(std::string name, Function::Kind kind, const Arity& arity, FunctionDoc doc, + const FunctionOptions* default_options) + : Function(std::move(name), kind, arity, std::move(doc), default_options) {} std::vector kernels_; }; @@ -305,10 +305,10 @@ class ARROW_EXPORT ScalarFunction : public detail::FunctionImpl { public: using KernelType = ScalarKernel; - ScalarFunction(std::string name, const Arity& arity, const FunctionDoc* doc, + ScalarFunction(std::string name, const Arity& arity, FunctionDoc doc, const FunctionOptions* default_options = NULLPTR) - : detail::FunctionImpl(std::move(name), Function::SCALAR, arity, doc, - default_options) {} + : detail::FunctionImpl(std::move(name), Function::SCALAR, arity, + std::move(doc), default_options) {} /// \brief Add a kernel with given input/output types, no required state /// initialization, preallocation for fixed-width types, and default null @@ -329,10 +329,10 @@ class ARROW_EXPORT VectorFunction : public detail::FunctionImpl { public: using KernelType = VectorKernel; - VectorFunction(std::string name, const Arity& arity, const FunctionDoc* doc, + VectorFunction(std::string name, const Arity& arity, FunctionDoc doc, const FunctionOptions* default_options = NULLPTR) - : detail::FunctionImpl(std::move(name), Function::VECTOR, arity, doc, - default_options) {} + : detail::FunctionImpl(std::move(name), Function::VECTOR, arity, + std::move(doc), default_options) {} /// \brief Add a simple kernel with given input/output types, no required /// state initialization, no data preallocation, and no preallocation of the @@ -350,10 +350,11 @@ class ARROW_EXPORT ScalarAggregateFunction public: using KernelType = ScalarAggregateKernel; - ScalarAggregateFunction(std::string name, const Arity& arity, const FunctionDoc* doc, + ScalarAggregateFunction(std::string name, const Arity& arity, FunctionDoc doc, const FunctionOptions* default_options = NULLPTR) - : detail::FunctionImpl( - std::move(name), Function::SCALAR_AGGREGATE, arity, doc, default_options) {} + : detail::FunctionImpl(std::move(name), + Function::SCALAR_AGGREGATE, arity, + std::move(doc), default_options) {} /// \brief Add a kernel (function implementation). Returns error if the /// kernel's signature does not match the function's arity. @@ -365,10 +366,11 @@ class ARROW_EXPORT HashAggregateFunction public: using KernelType = HashAggregateKernel; - HashAggregateFunction(std::string name, const Arity& arity, const FunctionDoc* doc, + HashAggregateFunction(std::string name, const Arity& arity, FunctionDoc doc, const FunctionOptions* default_options = NULLPTR) - : detail::FunctionImpl( - std::move(name), Function::HASH_AGGREGATE, arity, doc, default_options) {} + : detail::FunctionImpl(std::move(name), + Function::HASH_AGGREGATE, arity, + std::move(doc), default_options) {} /// \brief Add a kernel (function implementation). Returns error if the /// kernel's signature does not match the function's arity. @@ -392,9 +394,10 @@ class ARROW_EXPORT MetaFunction : public Function { const FunctionOptions* options, ExecContext* ctx) const = 0; - MetaFunction(std::string name, const Arity& arity, const FunctionDoc* doc, + MetaFunction(std::string name, const Arity& arity, FunctionDoc doc, const FunctionOptions* default_options = NULLPTR) - : Function(std::move(name), Function::META, arity, doc, default_options) {} + : Function(std::move(name), Function::META, arity, std::move(doc), + default_options) {} }; /// @} diff --git a/cpp/src/arrow/compute/function_test.cc b/cpp/src/arrow/compute/function_test.cc index 13de2a29ab8..94e86c7bd57 100644 --- a/cpp/src/arrow/compute/function_test.cc +++ b/cpp/src/arrow/compute/function_test.cc @@ -179,8 +179,9 @@ TEST(Arity, Basics) { } TEST(ScalarFunction, Basics) { - ScalarFunction func("scalar_test", Arity::Binary(), /*doc=*/nullptr); - ScalarFunction varargs_func("varargs_test", Arity::VarArgs(1), /*doc=*/nullptr); + ScalarFunction func("scalar_test", Arity::Binary(), /*doc=*/FunctionDoc::Empty()); + ScalarFunction varargs_func("varargs_test", Arity::VarArgs(1), + /*doc=*/FunctionDoc::Empty()); ASSERT_EQ("scalar_test", func.name()); ASSERT_EQ(2, func.arity().num_args); @@ -194,8 +195,9 @@ TEST(ScalarFunction, Basics) { } TEST(VectorFunction, Basics) { - VectorFunction func("vector_test", Arity::Binary(), /*doc=*/nullptr); - VectorFunction varargs_func("varargs_test", Arity::VarArgs(1), /*doc=*/nullptr); + VectorFunction func("vector_test", Arity::Binary(), /*doc=*/FunctionDoc::Empty()); + VectorFunction varargs_func("varargs_test", Arity::VarArgs(1), + /*doc=*/FunctionDoc::Empty()); ASSERT_EQ("vector_test", func.name()); ASSERT_EQ(2, func.arity().num_args); @@ -260,15 +262,15 @@ void CheckAddDispatch(FunctionType* func) { } TEST(ScalarVectorFunction, DispatchExact) { - ScalarFunction func1("scalar_test", Arity::Binary(), /*doc=*/nullptr); - VectorFunction func2("vector_test", Arity::Binary(), /*doc=*/nullptr); + ScalarFunction func1("scalar_test", Arity::Binary(), /*doc=*/FunctionDoc::Empty()); + VectorFunction func2("vector_test", Arity::Binary(), /*doc=*/FunctionDoc::Empty()); CheckAddDispatch(&func1); CheckAddDispatch(&func2); } TEST(ArrayFunction, VarArgs) { - ScalarFunction va_func("va_test", Arity::VarArgs(1), /*doc=*/nullptr); + ScalarFunction va_func("va_test", Arity::VarArgs(1), /*doc=*/FunctionDoc::Empty()); std::vector va_args = {int8()}; @@ -294,7 +296,7 @@ TEST(ArrayFunction, VarArgs) { } TEST(ScalarAggregateFunction, Basics) { - ScalarAggregateFunction func("agg_test", Arity::Unary(), /*doc=*/nullptr); + ScalarAggregateFunction func("agg_test", Arity::Unary(), /*doc=*/FunctionDoc::Empty()); ASSERT_EQ("agg_test", func.name()); ASSERT_EQ(1, func.arity().num_args); @@ -313,7 +315,7 @@ Status NoopMerge(KernelContext*, const KernelState&, KernelState*) { Status NoopFinalize(KernelContext*, Datum*) { return Status::OK(); } TEST(ScalarAggregateFunction, DispatchExact) { - ScalarAggregateFunction func("agg_test", Arity::Unary(), /*doc=*/nullptr); + ScalarAggregateFunction func("agg_test", Arity::Unary(), FunctionDoc::Empty()); std::vector in_args = {ValueDescr::Array(int8())}; ScalarAggregateKernel kernel(std::move(in_args), int64(), NoopInit, NoopConsume, diff --git a/cpp/src/arrow/compute/kernels/aggregate_basic.cc b/cpp/src/arrow/compute/kernels/aggregate_basic.cc index c9e2d85a26b..16495bc8030 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_basic.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_basic.cc @@ -918,7 +918,7 @@ void RegisterScalarAggregateBasic(FunctionRegistry* registry) { static auto default_count_options = CountOptions::Defaults(); auto func = std::make_shared( - "count", Arity::Unary(), &count_doc, &default_count_options); + "count", Arity::Unary(), count_doc, &default_count_options); // Takes any input, outputs int64 scalar InputType any_input; @@ -927,12 +927,12 @@ void RegisterScalarAggregateBasic(FunctionRegistry* registry) { DCHECK_OK(registry->AddFunction(std::move(func))); func = std::make_shared( - "count_distinct", Arity::Unary(), &count_distinct_doc, &default_count_options); + "count_distinct", Arity::Unary(), count_distinct_doc, &default_count_options); // Takes any input, outputs int64 scalar AddCountDistinctKernels(func.get()); DCHECK_OK(registry->AddFunction(std::move(func))); - func = std::make_shared("sum", Arity::Unary(), &sum_doc, + func = std::make_shared("sum", Arity::Unary(), sum_doc, &default_scalar_aggregate_options); AddArrayScalarAggKernels(SumInit, {boolean()}, uint64(), func.get()); AddAggKernel( @@ -961,7 +961,7 @@ void RegisterScalarAggregateBasic(FunctionRegistry* registry) { #endif DCHECK_OK(registry->AddFunction(std::move(func))); - func = std::make_shared("mean", Arity::Unary(), &mean_doc, + func = std::make_shared("mean", Arity::Unary(), mean_doc, &default_scalar_aggregate_options); AddArrayScalarAggKernels(MeanInit, {boolean()}, float64(), func.get()); AddArrayScalarAggKernels(MeanInit, NumericTypes(), float64(), func.get()); @@ -985,8 +985,8 @@ void RegisterScalarAggregateBasic(FunctionRegistry* registry) { #endif DCHECK_OK(registry->AddFunction(std::move(func))); - func = std::make_shared( - "min_max", Arity::Unary(), &min_max_doc, &default_scalar_aggregate_options); + func = std::make_shared("min_max", Arity::Unary(), min_max_doc, + &default_scalar_aggregate_options); AddMinMaxKernels(MinMaxInit, {null(), boolean()}, func.get()); AddMinMaxKernels(MinMaxInit, NumericTypes(), func.get()); AddMinMaxKernels(MinMaxInit, TemporalTypes(), func.get()); @@ -1011,18 +1011,18 @@ void RegisterScalarAggregateBasic(FunctionRegistry* registry) { DCHECK_OK(registry->AddFunction(std::move(func))); // Add min/max as convenience functions - func = std::make_shared("min", Arity::Unary(), &min_or_max_doc, + func = std::make_shared("min", Arity::Unary(), min_or_max_doc, &default_scalar_aggregate_options); AddMinOrMaxAggKernel(func.get(), min_max_func); DCHECK_OK(registry->AddFunction(std::move(func))); - func = std::make_shared("max", Arity::Unary(), &min_or_max_doc, + func = std::make_shared("max", Arity::Unary(), min_or_max_doc, &default_scalar_aggregate_options); AddMinOrMaxAggKernel(func.get(), min_max_func); DCHECK_OK(registry->AddFunction(std::move(func))); - func = std::make_shared( - "product", Arity::Unary(), &product_doc, &default_scalar_aggregate_options); + func = std::make_shared("product", Arity::Unary(), product_doc, + &default_scalar_aggregate_options); AddArrayScalarAggKernels(ProductInit::Init, {boolean()}, uint64(), func.get()); AddArrayScalarAggKernels(ProductInit::Init, SignedIntTypes(), int64(), func.get()); AddArrayScalarAggKernels(ProductInit::Init, UnsignedIntTypes(), uint64(), func.get()); @@ -1038,19 +1038,19 @@ void RegisterScalarAggregateBasic(FunctionRegistry* registry) { DCHECK_OK(registry->AddFunction(std::move(func))); // any - func = std::make_shared("any", Arity::Unary(), &any_doc, + func = std::make_shared("any", Arity::Unary(), any_doc, &default_scalar_aggregate_options); AddArrayScalarAggKernels(AnyInit, {boolean()}, boolean(), func.get()); DCHECK_OK(registry->AddFunction(std::move(func))); // all - func = std::make_shared("all", Arity::Unary(), &all_doc, + func = std::make_shared("all", Arity::Unary(), all_doc, &default_scalar_aggregate_options); AddArrayScalarAggKernels(AllInit, {boolean()}, boolean(), func.get()); DCHECK_OK(registry->AddFunction(std::move(func))); // index - func = std::make_shared("index", Arity::Unary(), &index_doc); + func = std::make_shared("index", Arity::Unary(), index_doc); AddBasicAggKernels(IndexInit::Init, BaseBinaryTypes(), int64(), func.get()); AddBasicAggKernels(IndexInit::Init, PrimitiveTypes(), int64(), func.get()); AddBasicAggKernels(IndexInit::Init, TemporalTypes(), int64(), func.get()); diff --git a/cpp/src/arrow/compute/kernels/aggregate_mode.cc b/cpp/src/arrow/compute/kernels/aggregate_mode.cc index 287c2c5d368..7d3440cbef3 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_mode.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_mode.cc @@ -428,7 +428,7 @@ const FunctionDoc mode_doc{ void RegisterScalarAggregateMode(FunctionRegistry* registry) { static auto default_options = ModeOptions::Defaults(); - auto func = std::make_shared("mode", Arity::Unary(), &mode_doc, + auto func = std::make_shared("mode", Arity::Unary(), mode_doc, &default_options); DCHECK_OK(func->AddKernel( NewModeKernel(boolean(), ModeExecutor::Exec))); diff --git a/cpp/src/arrow/compute/kernels/aggregate_quantile.cc b/cpp/src/arrow/compute/kernels/aggregate_quantile.cc index 1ca030130b0..810fb539913 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_quantile.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_quantile.cc @@ -531,7 +531,7 @@ const FunctionDoc quantile_doc{ void RegisterScalarAggregateQuantile(FunctionRegistry* registry) { static QuantileOptions default_options; - auto func = std::make_shared("quantile", Arity::Unary(), &quantile_doc, + auto func = std::make_shared("quantile", Arity::Unary(), quantile_doc, &default_options); AddQuantileKernels(func.get()); DCHECK_OK(registry->AddFunction(std::move(func))); diff --git a/cpp/src/arrow/compute/kernels/aggregate_tdigest.cc b/cpp/src/arrow/compute/kernels/aggregate_tdigest.cc index 7c86267d940..037bba42f16 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_tdigest.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_tdigest.cc @@ -196,7 +196,7 @@ const FunctionDoc approximate_median_doc{ std::shared_ptr AddTDigestAggKernels() { static auto default_tdigest_options = TDigestOptions::Defaults(); auto func = std::make_shared( - "tdigest", Arity::Unary(), &tdigest_doc, &default_tdigest_options); + "tdigest", Arity::Unary(), tdigest_doc, &default_tdigest_options); AddTDigestKernels(TDigestInit, NumericTypes(), func.get()); AddTDigestKernels(TDigestInit, {decimal128(1, 1), decimal256(1, 1)}, func.get()); return func; @@ -207,7 +207,7 @@ std::shared_ptr AddApproximateMedianAggKernels( static ScalarAggregateOptions default_scalar_aggregate_options; auto median = std::make_shared( - "approximate_median", Arity::Unary(), &approximate_median_doc, + "approximate_median", Arity::Unary(), approximate_median_doc, &default_scalar_aggregate_options); auto sig = diff --git a/cpp/src/arrow/compute/kernels/aggregate_var_std.cc b/cpp/src/arrow/compute/kernels/aggregate_var_std.cc index feb98718aee..1f9a26960b8 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_var_std.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_var_std.cc @@ -289,8 +289,8 @@ const FunctionDoc variance_doc{ std::shared_ptr AddStddevAggKernels() { static auto default_std_options = VarianceOptions::Defaults(); - auto func = std::make_shared( - "stddev", Arity::Unary(), &stddev_doc, &default_std_options); + auto func = std::make_shared("stddev", Arity::Unary(), + stddev_doc, &default_std_options); AddVarStdKernels(StddevInit, NumericTypes(), func.get()); AddVarStdKernels(StddevInit, {decimal128(1, 1), decimal256(1, 1)}, func.get()); return func; @@ -299,7 +299,7 @@ std::shared_ptr AddStddevAggKernels() { std::shared_ptr AddVarianceAggKernels() { static auto default_var_options = VarianceOptions::Defaults(); auto func = std::make_shared( - "variance", Arity::Unary(), &variance_doc, &default_var_options); + "variance", Arity::Unary(), variance_doc, &default_var_options); AddVarStdKernels(VarianceInit, NumericTypes(), func.get()); AddVarStdKernels(VarianceInit, {decimal128(1, 1), decimal256(1, 1)}, func.get()); return func; diff --git a/cpp/src/arrow/compute/kernels/hash_aggregate.cc b/cpp/src/arrow/compute/kernels/hash_aggregate.cc index db34ee6c596..d9ffcda5962 100644 --- a/cpp/src/arrow/compute/kernels/hash_aggregate.cc +++ b/cpp/src/arrow/compute/kernels/hash_aggregate.cc @@ -3554,7 +3554,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { { auto func = std::make_shared( - "hash_count", Arity::Binary(), &hash_count_doc, &default_count_options); + "hash_count", Arity::Binary(), hash_count_doc, &default_count_options); DCHECK_OK(func->AddKernel( MakeKernel(ValueDescr::ARRAY, HashAggregateInit))); @@ -3563,7 +3563,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { { auto func = std::make_shared( - "hash_sum", Arity::Binary(), &hash_sum_doc, &default_scalar_aggregate_options); + "hash_sum", Arity::Binary(), hash_sum_doc, &default_scalar_aggregate_options); DCHECK_OK(AddHashAggKernels({boolean()}, GroupedSumFactory::Make, func.get())); DCHECK_OK(AddHashAggKernels(SignedIntTypes(), GroupedSumFactory::Make, func.get())); DCHECK_OK(AddHashAggKernels(UnsignedIntTypes(), GroupedSumFactory::Make, func.get())); @@ -3578,7 +3578,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { { auto func = std::make_shared( - "hash_product", Arity::Binary(), &hash_product_doc, + "hash_product", Arity::Binary(), hash_product_doc, &default_scalar_aggregate_options); DCHECK_OK(AddHashAggKernels({boolean()}, GroupedProductFactory::Make, func.get())); DCHECK_OK( @@ -3596,7 +3596,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { { auto func = std::make_shared( - "hash_mean", Arity::Binary(), &hash_mean_doc, &default_scalar_aggregate_options); + "hash_mean", Arity::Binary(), hash_mean_doc, &default_scalar_aggregate_options); DCHECK_OK(AddHashAggKernels({boolean()}, GroupedMeanFactory::Make, func.get())); DCHECK_OK(AddHashAggKernels(SignedIntTypes(), GroupedMeanFactory::Make, func.get())); DCHECK_OK( @@ -3612,7 +3612,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { { auto func = std::make_shared( - "hash_stddev", Arity::Binary(), &hash_stddev_doc, &default_variance_options); + "hash_stddev", Arity::Binary(), hash_stddev_doc, &default_variance_options); DCHECK_OK(AddHashAggKernels(SignedIntTypes(), GroupedVarStdFactory::Make, func.get())); DCHECK_OK(AddHashAggKernels(UnsignedIntTypes(), @@ -3626,7 +3626,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { { auto func = std::make_shared( - "hash_variance", Arity::Binary(), &hash_variance_doc, &default_variance_options); + "hash_variance", Arity::Binary(), hash_variance_doc, &default_variance_options); DCHECK_OK(AddHashAggKernels(SignedIntTypes(), GroupedVarStdFactory::Make, func.get())); DCHECK_OK(AddHashAggKernels(UnsignedIntTypes(), @@ -3641,7 +3641,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { HashAggregateFunction* tdigest_func = nullptr; { auto func = std::make_shared( - "hash_tdigest", Arity::Binary(), &hash_tdigest_doc, &default_tdigest_options); + "hash_tdigest", Arity::Binary(), hash_tdigest_doc, &default_tdigest_options); DCHECK_OK( AddHashAggKernels(SignedIntTypes(), GroupedTDigestFactory::Make, func.get())); DCHECK_OK( @@ -3657,7 +3657,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { { auto func = std::make_shared( - "hash_approximate_median", Arity::Binary(), &hash_approximate_median_doc, + "hash_approximate_median", Arity::Binary(), hash_approximate_median_doc, &default_scalar_aggregate_options); DCHECK_OK(func->AddKernel(MakeApproximateMedianKernel(tdigest_func))); DCHECK_OK(registry->AddFunction(std::move(func))); @@ -3666,7 +3666,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { HashAggregateFunction* min_max_func = nullptr; { auto func = std::make_shared( - "hash_min_max", Arity::Binary(), &hash_min_max_doc, + "hash_min_max", Arity::Binary(), hash_min_max_doc, &default_scalar_aggregate_options); DCHECK_OK(AddHashAggKernels(NumericTypes(), GroupedMinMaxFactory::Make, func.get())); DCHECK_OK(AddHashAggKernels(TemporalTypes(), GroupedMinMaxFactory::Make, func.get())); @@ -3682,7 +3682,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { { auto func = std::make_shared( - "hash_min", Arity::Binary(), &hash_min_or_max_doc, + "hash_min", Arity::Binary(), hash_min_or_max_doc, &default_scalar_aggregate_options); DCHECK_OK(func->AddKernel(MakeMinOrMaxKernel(min_max_func))); DCHECK_OK(registry->AddFunction(std::move(func))); @@ -3690,7 +3690,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { { auto func = std::make_shared( - "hash_max", Arity::Binary(), &hash_min_or_max_doc, + "hash_max", Arity::Binary(), hash_min_or_max_doc, &default_scalar_aggregate_options); DCHECK_OK(func->AddKernel(MakeMinOrMaxKernel(min_max_func))); DCHECK_OK(registry->AddFunction(std::move(func))); @@ -3698,21 +3698,21 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { { auto func = std::make_shared( - "hash_any", Arity::Binary(), &hash_any_doc, &default_scalar_aggregate_options); + "hash_any", Arity::Binary(), hash_any_doc, &default_scalar_aggregate_options); DCHECK_OK(func->AddKernel(MakeKernel(boolean(), HashAggregateInit))); DCHECK_OK(registry->AddFunction(std::move(func))); } { auto func = std::make_shared( - "hash_all", Arity::Binary(), &hash_all_doc, &default_scalar_aggregate_options); + "hash_all", Arity::Binary(), hash_all_doc, &default_scalar_aggregate_options); DCHECK_OK(func->AddKernel(MakeKernel(boolean(), HashAggregateInit))); DCHECK_OK(registry->AddFunction(std::move(func))); } { auto func = std::make_shared( - "hash_count_distinct", Arity::Binary(), &hash_count_distinct_doc, + "hash_count_distinct", Arity::Binary(), hash_count_distinct_doc, &default_count_options); DCHECK_OK(func->AddKernel( MakeKernel(ValueDescr::ARRAY, GroupedDistinctInit))); @@ -3721,7 +3721,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { { auto func = std::make_shared( - "hash_distinct", Arity::Binary(), &hash_distinct_doc, &default_count_options); + "hash_distinct", Arity::Binary(), hash_distinct_doc, &default_count_options); DCHECK_OK(func->AddKernel( MakeKernel(ValueDescr::ARRAY, GroupedDistinctInit))); DCHECK_OK(registry->AddFunction(std::move(func))); @@ -3729,7 +3729,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { { auto func = std::make_shared("hash_one", Arity::Binary(), - &hash_one_doc); + hash_one_doc); DCHECK_OK(AddHashAggKernels(NumericTypes(), GroupedOneFactory::Make, func.get())); DCHECK_OK(AddHashAggKernels(TemporalTypes(), GroupedOneFactory::Make, func.get())); DCHECK_OK(AddHashAggKernels(BaseBinaryTypes(), GroupedOneFactory::Make, func.get())); @@ -3741,7 +3741,7 @@ void RegisterHashAggregateBasic(FunctionRegistry* registry) { { auto func = std::make_shared("hash_list", Arity::Binary(), - &hash_list_doc); + hash_list_doc); DCHECK_OK(AddHashAggKernels(NumericTypes(), GroupedListFactory::Make, func.get())); DCHECK_OK(AddHashAggKernels(TemporalTypes(), GroupedListFactory::Make, func.get())); DCHECK_OK(AddHashAggKernels(BaseBinaryTypes(), GroupedListFactory::Make, func.get())); diff --git a/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc b/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc index f53d9f0c7f0..4365ad4e768 100644 --- a/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc +++ b/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc @@ -1935,8 +1935,8 @@ void AddNullExec(ScalarFunction* func) { template std::shared_ptr MakeArithmeticFunction(std::string name, - const FunctionDoc* doc) { - auto func = std::make_shared(name, Arity::Binary(), doc); + FunctionDoc doc) { + auto func = std::make_shared(name, Arity::Binary(), std::move(doc)); for (const auto& ty : NumericTypes()) { auto exec = ArithmeticExecFromOp(ty); DCHECK_OK(func->AddKernel({ty, ty}, ty, exec)); @@ -1949,8 +1949,8 @@ std::shared_ptr MakeArithmeticFunction(std::string name, // only on non-null output. template std::shared_ptr MakeArithmeticFunctionNotNull(std::string name, - const FunctionDoc* doc) { - auto func = std::make_shared(name, Arity::Binary(), doc); + FunctionDoc doc) { + auto func = std::make_shared(name, Arity::Binary(), std::move(doc)); for (const auto& ty : NumericTypes()) { auto exec = ArithmeticExecFromOp(ty); DCHECK_OK(func->AddKernel({ty, ty}, ty, exec)); @@ -1961,8 +1961,8 @@ std::shared_ptr MakeArithmeticFunctionNotNull(std::string name, template std::shared_ptr MakeUnaryArithmeticFunction(std::string name, - const FunctionDoc* doc) { - auto func = std::make_shared(name, Arity::Unary(), doc); + FunctionDoc doc) { + auto func = std::make_shared(name, Arity::Unary(), std::move(doc)); for (const auto& ty : NumericTypes()) { auto exec = ArithmeticExecFromOp(ty); DCHECK_OK(func->AddKernel({ty}, ty, exec)); @@ -1975,9 +1975,9 @@ std::shared_ptr MakeUnaryArithmeticFunction(std::string name, // output type for integral inputs. template std::shared_ptr MakeUnaryArithmeticFunctionWithFixedIntOutType( - std::string name, const FunctionDoc* doc) { + std::string name, FunctionDoc doc) { auto int_out_ty = TypeTraits::type_singleton(); - auto func = std::make_shared(name, Arity::Unary(), doc); + auto func = std::make_shared(name, Arity::Unary(), std::move(doc)); for (const auto& ty : NumericTypes()) { auto out_ty = arrow::is_floating(ty->id()) ? ty : int_out_ty; auto exec = GenerateArithmeticWithFixedIntOutType(ty); @@ -1996,9 +1996,9 @@ std::shared_ptr MakeUnaryArithmeticFunctionWithFixedIntOutType( // Like MakeUnaryArithmeticFunction, but for arithmetic ops that need to run // only on non-null output. template -std::shared_ptr MakeUnaryArithmeticFunctionNotNull( - std::string name, const FunctionDoc* doc) { - auto func = std::make_shared(name, Arity::Unary(), doc); +std::shared_ptr MakeUnaryArithmeticFunctionNotNull(std::string name, + FunctionDoc doc) { + auto func = std::make_shared(name, Arity::Unary(), std::move(doc)); for (const auto& ty : NumericTypes()) { auto exec = ArithmeticExecFromOp(ty); DCHECK_OK(func->AddKernel({ty}, ty, exec)); @@ -2075,11 +2075,11 @@ Status ExecRound(KernelContext* ctx, const ExecBatch& batch, Datum* out) { // kernel dispatch based on RoundMode, only on non-null output. template