diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt index eea19e54954..91e67fb423a 100644 --- a/cpp/src/arrow/CMakeLists.txt +++ b/cpp/src/arrow/CMakeLists.txt @@ -363,6 +363,7 @@ if(ARROW_COMPUTE) compute/kernels/scalar_set_lookup.cc compute/kernels/scalar_string.cc compute/kernels/scalar_validity.cc + compute/kernels/scalar_fill_null.cc compute/kernels/util_internal.cc compute/kernels/vector_hash.cc compute/kernels/vector_nested.cc diff --git a/cpp/src/arrow/compute/api_scalar.cc b/cpp/src/arrow/compute/api_scalar.cc index 1b2b8991d9b..77893f74fcd 100644 --- a/cpp/src/arrow/compute/api_scalar.cc +++ b/cpp/src/arrow/compute/api_scalar.cc @@ -126,5 +126,9 @@ Result Compare(const Datum& left, const Datum& right, CompareOptions opti SCALAR_EAGER_UNARY(IsValid, "is_valid") SCALAR_EAGER_UNARY(IsNull, "is_null") +Result FillNull(const Datum& values, const Datum& fill_value, ExecContext* ctx) { + return CallFunction("fill_null", {values, fill_value}, ctx); +} + } // namespace compute } // namespace arrow diff --git a/cpp/src/arrow/compute/api_scalar.h b/cpp/src/arrow/compute/api_scalar.h index d513173d76f..858e1ff6a19 100644 --- a/cpp/src/arrow/compute/api_scalar.h +++ b/cpp/src/arrow/compute/api_scalar.h @@ -259,6 +259,21 @@ Result IsValid(const Datum& values, ExecContext* ctx = NULLPTR); ARROW_EXPORT Result IsNull(const Datum& values, ExecContext* ctx = NULLPTR); +/// \brief FillNull replaces each null element in `values` +/// with `fill_value` +/// +/// \param[in] values input to examine for nullity +/// \param[in] fill_value scalar +/// \param[in] ctx the function execution context, optional +/// +/// \return the resulting datum +/// +/// \since 1.0.0 +/// \note API not yet finalized +ARROW_EXPORT +Result FillNull(const Datum& values, const Datum& fill_value, + ExecContext* ctx = NULLPTR); + // ---------------------------------------------------------------------- // String functions diff --git a/cpp/src/arrow/compute/kernels/CMakeLists.txt b/cpp/src/arrow/compute/kernels/CMakeLists.txt index e693a4176ab..fc147e3a69b 100644 --- a/cpp/src/arrow/compute/kernels/CMakeLists.txt +++ b/cpp/src/arrow/compute/kernels/CMakeLists.txt @@ -28,6 +28,7 @@ add_arrow_compute_test(scalar_test scalar_set_lookup_test.cc scalar_string_test.cc scalar_validity_test.cc + scalar_fill_null_test.cc test_util.cc) add_arrow_benchmark(scalar_arithmetic_benchmark PREFIX "arrow-compute") diff --git a/cpp/src/arrow/compute/kernels/codegen_internal.h b/cpp/src/arrow/compute/kernels/codegen_internal.h index 32b62ef0df2..4d8918ae773 100644 --- a/cpp/src/arrow/compute/kernels/codegen_internal.h +++ b/cpp/src/arrow/compute/kernels/codegen_internal.h @@ -852,6 +852,46 @@ ArrayKernelExec GenerateSignedInteger(detail::GetTypeId get_id) { } } +// Generate a kernel given a templated functor. Only a single template is +// instantiated for each bit width, and the functor is expected to treat types +// of the same bit width the same without utilizing any type-specific behavior +// (e.g. int64 should be handled equivalent to uint64 or double -- all 64 +// bits). +// +// See "Numeric" above for description of the generator functor +template