]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/cpp/src/arrow/compute/registry.h
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / arrow / compute / registry.h
CommitLineData
1d09f67e
TL
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18// NOTE: API is EXPERIMENTAL and will change without going through a
19// deprecation cycle
20
21#pragma once
22
23#include <memory>
24#include <string>
25#include <vector>
26
27#include "arrow/result.h"
28#include "arrow/status.h"
29#include "arrow/util/visibility.h"
30
31namespace arrow {
32namespace compute {
33
34class Function;
35class FunctionOptionsType;
36
37/// \brief A mutable central function registry for built-in functions as well
38/// as user-defined functions. Functions are implementations of
39/// arrow::compute::Function.
40///
41/// Generally, each function contains kernels which are implementations of a
42/// function for a specific argument signature. After looking up a function in
43/// the registry, one can either execute it eagerly with Function::Execute or
44/// use one of the function's dispatch methods to pick a suitable kernel for
45/// lower-level function execution.
46class ARROW_EXPORT FunctionRegistry {
47 public:
48 ~FunctionRegistry();
49
50 /// \brief Construct a new registry. Most users only need to use the global
51 /// registry
52 static std::unique_ptr<FunctionRegistry> Make();
53
54 /// \brief Add a new function to the registry. Returns Status::KeyError if a
55 /// function with the same name is already registered
56 Status AddFunction(std::shared_ptr<Function> function, bool allow_overwrite = false);
57
58 /// \brief Add aliases for the given function name. Returns Status::KeyError if the
59 /// function with the given name is not registered
60 Status AddAlias(const std::string& target_name, const std::string& source_name);
61
62 /// \brief Add a new function options type to the registry. Returns Status::KeyError if
63 /// a function options type with the same name is already registered
64 Status AddFunctionOptionsType(const FunctionOptionsType* options_type,
65 bool allow_overwrite = false);
66
67 /// \brief Retrieve a function by name from the registry
68 Result<std::shared_ptr<Function>> GetFunction(const std::string& name) const;
69
70 /// \brief Return vector of all entry names in the registry. Helpful for
71 /// displaying a manifest of available functions
72 std::vector<std::string> GetFunctionNames() const;
73
74 /// \brief Retrieve a function options type by name from the registry
75 Result<const FunctionOptionsType*> GetFunctionOptionsType(
76 const std::string& name) const;
77
78 /// \brief The number of currently registered functions
79 int num_functions() const;
80
81 private:
82 FunctionRegistry();
83
84 // Use PIMPL pattern to not have std::unordered_map here
85 class FunctionRegistryImpl;
86 std::unique_ptr<FunctionRegistryImpl> impl_;
87};
88
89/// \brief Return the process-global function registry
90ARROW_EXPORT FunctionRegistry* GetFunctionRegistry();
91
92} // namespace compute
93} // namespace arrow