niyue commented on code in PR #38116:
URL: https://github.com/apache/arrow/pull/38116#discussion_r1381130797
##########
cpp/src/gandiva/function_registry.cc:
##########
@@ -41,42 +62,80 @@ FunctionRegistry::iterator FunctionRegistry::back() const {
return &(pc_registry_.back());
}
-std::vector<NativeFunction> FunctionRegistry::pc_registry_;
+const NativeFunction* FunctionRegistry::LookupSignature(
+ const FunctionSignature& signature) const {
+ auto got = pc_registry_map_.find(&signature);
+ return got == pc_registry_map_.end() ? nullptr : got->second;
+}
+
+Status FunctionRegistry::Add(NativeFunction func) {
+ if (pc_registry_.size() == kMaxFunctionSignatures) {
+ return Status::CapacityError("Exceeded max function signatures limit of ",
+ kMaxFunctionSignatures);
+ }
+ pc_registry_.emplace_back(std::move(func));
+ auto const& last_func = pc_registry_.back();
+ for (auto const& func_signature : last_func.signatures()) {
+ pc_registry_map_.emplace(&func_signature, &last_func);
+ }
+ return arrow::Status::OK();
+}
-SignatureMap FunctionRegistry::pc_registry_map_ = InitPCMap();
+arrow::Result<std::unique_ptr<llvm::MemoryBuffer>> GetBufferFromFile(
+ const std::string& bitcode_file_path) {
+ auto buffer_or_error = llvm::MemoryBuffer::getFile(bitcode_file_path);
-SignatureMap FunctionRegistry::InitPCMap() {
- SignatureMap map;
+ ARROW_RETURN_IF(!buffer_or_error,
+ Status::IOError("Could not load module from bitcode file: ",
+ bitcode_file_path +
+ " Error: " +
buffer_or_error.getError().message()));
- auto v1 = GetArithmeticFunctionRegistry();
- pc_registry_.insert(std::end(pc_registry_), v1.begin(), v1.end());
- auto v2 = GetDateTimeFunctionRegistry();
- pc_registry_.insert(std::end(pc_registry_), v2.begin(), v2.end());
+ auto buffer = std::move(buffer_or_error.get());
+ return std::move(buffer);
+}
- auto v3 = GetHashFunctionRegistry();
- pc_registry_.insert(std::end(pc_registry_), v3.begin(), v3.end());
+Status FunctionRegistry::Register(const std::vector<NativeFunction>& funcs,
+ const std::string& bitcode_path) {
+ ARROW_ASSIGN_OR_RAISE(auto llvm_buffer, GetBufferFromFile(bitcode_path));
+ auto buffer =
std::make_unique<LLVMMemoryArrowBuffer>(std::move(llvm_buffer));
Review Comment:
Fixed
--
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]