Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cpp/src/arrow/compute/exec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "arrow/chunked_array.h"
#include "arrow/compute/exec_internal.h"
#include "arrow/compute/function.h"
#include "arrow/compute/function_internal.h"
#include "arrow/compute/kernel.h"
#include "arrow/compute/registry.h"
#include "arrow/datum.h"
Expand Down Expand Up @@ -883,6 +884,7 @@ class ScalarExecutor : public KernelExecutorImpl<ScalarKernel> {
}
}
if (kernel_->mem_allocation == MemAllocation::PREALLOCATE) {
data_preallocated_.clear();
ComputeDataPreallocate(*output_type_.type, &data_preallocated_);
}

Expand Down Expand Up @@ -966,6 +968,7 @@ class VectorExecutor : public KernelExecutorImpl<VectorKernel> {
(kernel_->null_handling != NullHandling::COMPUTED_NO_PREALLOCATE &&
kernel_->null_handling != NullHandling::OUTPUT_NOT_NULL);
if (kernel_->mem_allocation == MemAllocation::PREALLOCATE) {
data_preallocated_.clear();
ComputeDataPreallocate(*output_type_.type, &data_preallocated_);
}

Expand Down Expand Up @@ -1316,5 +1319,25 @@ Result<Datum> CallFunction(const std::string& func_name, const ExecBatch& batch,
return CallFunction(func_name, batch, /*options=*/nullptr, ctx);
}

Result<std::shared_ptr<FunctionExecutor>> GetFunctionExecutor(
const std::string& func_name, std::vector<TypeHolder> in_types,
const FunctionOptions* options, FunctionRegistry* func_registry) {
if (func_registry == NULLPTR) {
func_registry = GetFunctionRegistry();
}
ARROW_ASSIGN_OR_RAISE(std::shared_ptr<const Function> func,
func_registry->GetFunction(func_name));
ARROW_ASSIGN_OR_RAISE(auto func_exec, func->GetBestExecutor(std::move(in_types)));
ARROW_RETURN_NOT_OK(func_exec->Init(options));
return func_exec;
}

Result<std::shared_ptr<FunctionExecutor>> GetFunctionExecutor(
const std::string& func_name, const std::vector<Datum>& args,
const FunctionOptions* options, FunctionRegistry* func_registry) {
ARROW_ASSIGN_OR_RAISE(auto in_types, internal::GetFunctionArgumentTypes(args));
return GetFunctionExecutor(func_name, std::move(in_types), options, func_registry);
}

} // namespace compute
} // namespace arrow
28 changes: 25 additions & 3 deletions cpp/src/arrow/compute/exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ class CpuInfo;

namespace compute {

class FunctionOptions;
class FunctionRegistry;

// It seems like 64K might be a good default chunksize to use for execution
// based on the experience of other query processing systems. The current
// default is not to chunk contiguous arrays, though, but this may change in
Expand Down Expand Up @@ -440,5 +437,30 @@ Result<Datum> CallFunction(const std::string& func_name, const ExecBatch& batch,

/// @}

/// \defgroup compute-function-executor One-shot calls to obtain function executors
///
/// @{

/// \brief One-shot executor provider for all types of functions.
///
/// This function creates and initializes a `FunctionExecutor` appropriate
/// for the given function name, input types and function options.
ARROW_EXPORT
Result<std::shared_ptr<FunctionExecutor>> GetFunctionExecutor(
const std::string& func_name, std::vector<TypeHolder> in_types,
const FunctionOptions* options = NULLPTR, FunctionRegistry* func_registry = NULLPTR);

/// \brief One-shot executor provider for all types of functions.
///
/// This function creates and initializes a `FunctionExecutor` appropriate
/// for the given function name, input types (taken from the Datum arguments)
/// and function options.
ARROW_EXPORT
Result<std::shared_ptr<FunctionExecutor>> GetFunctionExecutor(
const std::string& func_name, const std::vector<Datum>& args,
const FunctionOptions* options = NULLPTR, FunctionRegistry* func_registry = NULLPTR);

/// @}

} // namespace compute
} // namespace arrow
Loading