This is an automated email from the ASF dual-hosted git repository. kszucs pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push: new dd2f8ae ARROW-9286: [C++] Add function "aliases" to compute::FunctionRegistry dd2f8ae is described below commit dd2f8ae967b56ec830292266646e42d41432d735 Author: tianchen <tianc...@apache.org> AuthorDate: Wed Jul 29 13:11:04 2020 +0200 ARROW-9286: [C++] Add function "aliases" to compute::FunctionRegistry Closes #7851 from tianchen92/ARROW-9286 Authored-by: tianchen <tianc...@apache.org> Signed-off-by: Krisztián Szűcs <szucs.kriszt...@gmail.com> --- cpp/src/arrow/compute/registry.cc | 14 ++++++++++++++ cpp/src/arrow/compute/registry.h | 4 ++++ cpp/src/arrow/compute/registry_test.cc | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/cpp/src/arrow/compute/registry.cc b/cpp/src/arrow/compute/registry.cc index ed9f38f..d880d97 100644 --- a/cpp/src/arrow/compute/registry.cc +++ b/cpp/src/arrow/compute/registry.cc @@ -45,6 +45,15 @@ class FunctionRegistry::FunctionRegistryImpl { return Status::OK(); } + Status AddAlias(const std::string& target_name, const std::string& source_name) { + auto it = name_to_function_.find(source_name); + if (it == name_to_function_.end()) { + return Status::KeyError("No function registered with name: ", source_name); + } + name_to_function_[target_name] = it->second; + return Status::OK(); + } + Result<std::shared_ptr<Function>> GetFunction(const std::string& name) const { auto it = name_to_function_.find(name); if (it == name_to_function_.end()) { @@ -82,6 +91,11 @@ Status FunctionRegistry::AddFunction(std::shared_ptr<Function> function, return impl_->AddFunction(std::move(function), allow_overwrite); } +Status FunctionRegistry::AddAlias(const std::string& target_name, + const std::string& source_name) { + return impl_->AddAlias(target_name, source_name); +} + Result<std::shared_ptr<Function>> FunctionRegistry::GetFunction( const std::string& name) const { return impl_->GetFunction(name); diff --git a/cpp/src/arrow/compute/registry.h b/cpp/src/arrow/compute/registry.h index 2d4c40b..b4456dc 100644 --- a/cpp/src/arrow/compute/registry.h +++ b/cpp/src/arrow/compute/registry.h @@ -54,6 +54,10 @@ class ARROW_EXPORT FunctionRegistry { /// function with the same name is already registered Status AddFunction(std::shared_ptr<Function> function, bool allow_overwrite = false); + /// \brief Add aliases for the given function name. Returns Status::KeyError if the + /// function with the given name is not registered + Status AddAlias(const std::string& target_name, const std::string& source_name); + /// \brief Retrieve a function by name from the registry Result<std::shared_ptr<Function>> GetFunction(const std::string& name) const; diff --git a/cpp/src/arrow/compute/registry_test.cc b/cpp/src/arrow/compute/registry_test.cc index 6218b31..67a7224 100644 --- a/cpp/src/arrow/compute/registry_test.cc +++ b/cpp/src/arrow/compute/registry_test.cc @@ -74,6 +74,12 @@ TEST_F(TestRegistry, Basics) { std::vector<std::string> expected_names = {"f0", "f1"}; ASSERT_EQ(expected_names, registry_->GetFunctionNames()); + + // Aliases + ASSERT_RAISES(KeyError, registry_->AddAlias("f33", "f3")); + ASSERT_OK(registry_->AddAlias("f11", "f1")); + ASSERT_OK_AND_ASSIGN(std::shared_ptr<const Function> f2, registry_->GetFunction("f11")); + ASSERT_EQ(func, f2); } } // namespace compute