vibhatha commented on code in PR #13375:
URL: https://github.com/apache/arrow/pull/13375#discussion_r896736948
##########
cpp/src/arrow/compute/registry.cc:
##########
@@ -98,14 +111,96 @@ class FunctionRegistry::FunctionRegistryImpl {
const std::string& name) const {
auto it = name_to_options_type_.find(name);
if (it == name_to_options_type_.end()) {
+ if (parent_ != NULLPTR) {
+ return parent_->GetFunctionOptionsType(name);
+ }
return Status::KeyError("No function options type registered with name:
", name);
}
return it->second;
}
- int num_functions() const { return
static_cast<int>(name_to_function_.size()); }
+ int num_functions() const {
+ return (parent_ == NULLPTR ? 0 : parent_->num_functions()) +
+ static_cast<int>(name_to_function_.size());
+ }
private:
+ // must not acquire mutex
+ Status CanAddFunctionName(const std::string& name, bool allow_overwrite) {
+ if (parent_ != NULLPTR) {
+ RETURN_NOT_OK(parent_->CanAddFunctionName(name, allow_overwrite));
+ }
+ if (!allow_overwrite) {
+ auto it = name_to_function_.find(name);
+ if (it != name_to_function_.end()) {
+ return Status::KeyError("Already have a function registered with name:
", name);
+ }
+ }
+ return Status::OK();
+ }
+
+ // must not acquire mutex
+ Status CanAddOptionsTypeName(const std::string& name, bool allow_overwrite) {
+ if (parent_ != NULLPTR) {
+ RETURN_NOT_OK(parent_->CanAddOptionsTypeName(name, allow_overwrite));
+ }
+ if (!allow_overwrite) {
+ auto it = name_to_options_type_.find(name);
+ if (it != name_to_options_type_.end()) {
+ return Status::KeyError(
+ "Already have a function options type registered with name: ",
name);
+ }
+ }
+ return Status::OK();
+ }
+
+ Status DoAddFunction(std::shared_ptr<Function> function, bool
allow_overwrite,
+ bool add) {
+#ifndef NDEBUG
+ // This validates docstrings extensively, so don't waste time on it
+ // in release builds.
+ RETURN_NOT_OK(function->Validate());
+#endif
+
+ std::lock_guard<std::mutex> mutation_guard(lock_);
+
+ const std::string& name = function->name();
+ RETURN_NOT_OK(CanAddFunctionName(name, allow_overwrite));
+ if (add) {
+ name_to_function_[name] = std::move(function);
+ }
+ return Status::OK();
+ }
+
+ Status DoAddAlias(const std::string& target_name, const std::string&
source_name,
+ bool add) {
+ // source name must exist in this registry or the parent
+ // check outside mutex, in case GetFunction leads to mutex acquisition
+ ARROW_ASSIGN_OR_RAISE(auto func, GetFunction(source_name));
+
+ std::lock_guard<std::mutex> mutation_guard(lock_);
+
+ // target name must be available in this registry and the parent
+ RETURN_NOT_OK(CanAddFunctionName(target_name, /*allow_overwrite=*/false));
Review Comment:
do we need to mention `/*allow_overwrite=*/` here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]