![]() |
|
|||
File indexing completed on 2025-08-28 08:26:57
0001 // Licensed to the Apache Software Foundation (ASF) under one 0002 // or more contributor license agreements. See the NOTICE file 0003 // distributed with this work for additional information 0004 // regarding copyright ownership. The ASF licenses this file 0005 // to you under the Apache License, Version 2.0 (the 0006 // "License"); you may not use this file except in compliance 0007 // with the License. You may obtain a copy of the License at 0008 // 0009 // http://www.apache.org/licenses/LICENSE-2.0 0010 // 0011 // Unless required by applicable law or agreed to in writing, 0012 // software distributed under the License is distributed on an 0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 0014 // KIND, either express or implied. See the License for the 0015 // specific language governing permissions and limitations 0016 // under the License. 0017 0018 // NOTE: API is EXPERIMENTAL and will change without going through a 0019 // deprecation cycle 0020 0021 #pragma once 0022 0023 #include <memory> 0024 #include <string> 0025 #include <vector> 0026 0027 #include "arrow/result.h" 0028 #include "arrow/status.h" 0029 #include "arrow/util/visibility.h" 0030 0031 namespace arrow { 0032 namespace compute { 0033 0034 class Function; 0035 class FunctionOptionsType; 0036 0037 /// \brief A mutable central function registry for built-in functions as well 0038 /// as user-defined functions. Functions are implementations of 0039 /// arrow::compute::Function. 0040 /// 0041 /// Generally, each function contains kernels which are implementations of a 0042 /// function for a specific argument signature. After looking up a function in 0043 /// the registry, one can either execute it eagerly with Function::Execute or 0044 /// use one of the function's dispatch methods to pick a suitable kernel for 0045 /// lower-level function execution. 0046 class ARROW_EXPORT FunctionRegistry { 0047 public: 0048 ~FunctionRegistry(); 0049 0050 /// \brief Construct a new registry. 0051 /// 0052 /// Most users only need to use the global registry. 0053 static std::unique_ptr<FunctionRegistry> Make(); 0054 0055 /// \brief Construct a new nested registry with the given parent. 0056 /// 0057 /// Most users only need to use the global registry. The returned registry never changes 0058 /// its parent, even when an operation allows overwriting. 0059 static std::unique_ptr<FunctionRegistry> Make(FunctionRegistry* parent); 0060 0061 /// \brief Check whether a new function can be added to the registry. 0062 /// 0063 /// \returns Status::KeyError if a function with the same name is already registered. 0064 Status CanAddFunction(std::shared_ptr<Function> function, bool allow_overwrite = false); 0065 0066 /// \brief Add a new function to the registry. 0067 /// 0068 /// \returns Status::KeyError if a function with the same name is already registered. 0069 Status AddFunction(std::shared_ptr<Function> function, bool allow_overwrite = false); 0070 0071 /// \brief Check whether an alias can be added for the given function name. 0072 /// 0073 /// \returns Status::KeyError if the function with the given name is not registered. 0074 Status CanAddAlias(const std::string& target_name, const std::string& source_name); 0075 0076 /// \brief Add alias for the given function name. 0077 /// 0078 /// \returns Status::KeyError if the function with the given name is not registered. 0079 Status AddAlias(const std::string& target_name, const std::string& source_name); 0080 0081 /// \brief Check whether a new function options type can be added to the registry. 0082 /// 0083 /// \return Status::KeyError if a function options type with the same name is already 0084 /// registered. 0085 Status CanAddFunctionOptionsType(const FunctionOptionsType* options_type, 0086 bool allow_overwrite = false); 0087 0088 /// \brief Add a new function options type to the registry. 0089 /// 0090 /// \returns Status::KeyError if a function options type with the same name is already 0091 /// registered. 0092 Status AddFunctionOptionsType(const FunctionOptionsType* options_type, 0093 bool allow_overwrite = false); 0094 0095 /// \brief Retrieve a function by name from the registry. 0096 Result<std::shared_ptr<Function>> GetFunction(const std::string& name) const; 0097 0098 /// \brief Return vector of all entry names in the registry. 0099 /// 0100 /// Helpful for displaying a manifest of available functions. 0101 std::vector<std::string> GetFunctionNames() const; 0102 0103 /// \brief Retrieve a function options type by name from the registry. 0104 Result<const FunctionOptionsType*> GetFunctionOptionsType( 0105 const std::string& name) const; 0106 0107 /// \brief The number of currently registered functions. 0108 int num_functions() const; 0109 0110 /// \brief The cast function object registered in AddFunction. 0111 /// 0112 /// Helpful for get cast function as needed. 0113 const Function* cast_function() const; 0114 0115 private: 0116 FunctionRegistry(); 0117 0118 // Use PIMPL pattern to not have std::unordered_map here 0119 class FunctionRegistryImpl; 0120 std::unique_ptr<FunctionRegistryImpl> impl_; 0121 0122 explicit FunctionRegistry(FunctionRegistryImpl* impl); 0123 }; 0124 0125 } // namespace compute 0126 } // namespace arrow
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |