github-actions[bot] commented on code in PR #30789:
URL: https://github.com/apache/doris/pull/30789#discussion_r1477178731


##########
be/src/util/wasm_manager.cpp:
##########
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/wasm_manager.h"
+
+namespace doris {
+
+WasmFunctionManager::WasmFunctionManager() {

Review Comment:
   warning: use '= default' to define a trivial default constructor 
[modernize-use-equals-default]
   ```cpp
   WasmFunctionManager::WasmFunctionManager() {
                        ^
   ```
   



##########
be/src/runtime/user_function_cache.cpp:
##########
@@ -370,6 +375,14 @@ Status UserFunctionCache::get_jarpath(int64_t fid, const 
std::string& url,
     return Status::OK();
 }
 
+Status UserFunctionCache::get_watpath(int64_t fid, const std::string& url,

Review Comment:
   warning: method 'get_watpath' can be made static 
[readability-convert-member-functions-to-static]
   
   ```suggestion
   static Status UserFunctionCache::get_watpath(int64_t fid, const std::string& 
url,
   ```
   



##########
be/src/vec/functions/function_wasm.h:
##########
@@ -0,0 +1,82 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <fmt/format.h>

Review Comment:
   warning: 'fmt/format.h' file not found [clang-diagnostic-error]
   ```cpp
   #include <fmt/format.h>
            ^
   ```
   



##########
be/src/vec/functions/function_wasm.h:
##########
@@ -0,0 +1,82 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <fmt/format.h>
+#include <stddef.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "common/status.h"
+#include "udf/udf.h"
+#include "util/wasm_manager.h"
+#include "vec/core/block.h"
+#include "vec/core/column_numbers.h"
+#include "vec/core/column_with_type_and_name.h"
+#include "vec/core/columns_with_type_and_name.h"
+#include "vec/core/types.h"
+#include "vec/data_types/data_type.h"
+#include "vec/functions/function.h"
+
+namespace doris::vectorized {
+
+class FunctionWasm : public IFunctionBase {
+public:
+    FunctionWasm(const TFunction& fn, const DataTypes& argument_types,
+                 const DataTypePtr& return_type);
+
+    static FunctionBasePtr create(const TFunction& fn, const 
ColumnsWithTypeAndName& argument_types,
+                                  const DataTypePtr& return_type) {
+        DataTypes data_types(argument_types.size());
+        for (size_t i = 0; i < argument_types.size(); ++i) {
+            data_types[i] = argument_types[i].type;
+        }
+        return std::make_shared<FunctionWasm>(fn, data_types, return_type);
+    }
+
+    /// Get the main function name.
+    String get_name() const override {
+        return fmt::format("{}: [{}/{}]", _tfn.name.function_name, 
_tfn.hdfs_location,
+                           _tfn.scalar_fn.symbol);
+    }
+
+    const DataTypes& get_argument_types() const override { return 
_argument_types; }
+    const DataTypePtr& get_return_type() const override { return _return_type; 
}
+
+    PreparedFunctionPtr prepare(FunctionContext* context, const Block& 
sample_block,
+                                const ColumnNumbers& arguments, size_t result) 
const override {

Review Comment:
   warning: method 'prepare' can be made static 
[readability-convert-member-functions-to-static]
   
   ```suggestion
       static PreparedFunctionPtr prepare(FunctionContext* context, const 
Block& sample_block,
                                   const ColumnNumbers& arguments, size_t 
result) override {
   ```
   



##########
be/test/util/wasm_manager_test.cpp:
##########
@@ -0,0 +1,57 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/wasm_manager.h"
+
+#include <gtest/gtest-message.h>
+#include <gtest/gtest-test-part.h>
+
+#include <fstream>
+#include <string>
+
+#include "gtest/gtest_pred_impl.h"
+#include "testutil/test_util.h"
+
+namespace doris {
+
+class WasmManagerTest : public ::testing::Test {
+    std::string readFile(const char* name) {

Review Comment:
   warning: method 'readFile' can be made static 
[readability-convert-member-functions-to-static]
   
   ```suggestion
       static std::string readFile(const char* name) {
   ```
   



##########
be/src/util/wasm_manager.h:
##########
@@ -0,0 +1,65 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <cassert>
+#include <fstream>
+#include <iostream>
+#include <limits>
+#include <sstream>
+#include <string>
+#include <unordered_map>
+#include <vector>
+#include <wasmtime.hh>

Review Comment:
   warning: 'wasmtime.hh' file not found [clang-diagnostic-error]
   ```cpp
   #include <wasmtime.hh>
            ^
   ```
   



##########
be/src/util/wasm_manager.cpp:
##########
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/wasm_manager.h"
+
+namespace doris {
+
+WasmFunctionManager::WasmFunctionManager() {
+    engine = std::unique_ptr<wasmtime::Engine>(new wasmtime::Engine);
+    store = std::unique_ptr<wasmtime::Store>(new wasmtime::Store(*engine));
+}
+
+WasmFunctionManager::~WasmFunctionManager() {
+    engine.reset();
+    store.reset();
+}
+
+bool WasmFunctionManager::RegisterFunction(std::string functionName, 
std::string functionHandler,
+                                           const std::string& watString) {
+    auto funcBody = funcs.find(functionName);
+    if (funcBody != funcs.end()) {
+        return false;
+    }
+    auto wasmRuntime = createInstanceAndFunction(watString, functionHandler);
+    funcs.emplace(functionName, wasmRuntime);
+    return true;
+}
+
+bool WasmFunctionManager::RegisterFunction(std::string functionName, 
std::string functionHandler,
+                                           const wasmtime::Span<uint8_t>& 
wasm) {
+    auto funcBody = funcs.find(functionName);
+    if (funcBody != funcs.end()) {
+        return false;
+    }
+    auto wasmRuntime = createInstanceAndFunction(wasm, functionHandler);
+    funcs.emplace(functionName, wasmRuntime);
+    return true;
+}
+
+WasmtimeRunInstance WasmFunctionManager::createInstanceAndFunction(

Review Comment:
   warning: method 'createInstanceAndFunction' can be made static 
[readability-convert-member-functions-to-static]
   
   be/src/util/wasm_manager.h:51:
   ```diff
   -     WasmtimeRunInstance createInstanceAndFunction(const std::string& 
watString,
   +     static WasmtimeRunInstance createInstanceAndFunction(const 
std::string& watString,
   ```
   



##########
be/src/util/wasm_manager.cpp:
##########
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/wasm_manager.h"
+
+namespace doris {
+
+WasmFunctionManager::WasmFunctionManager() {
+    engine = std::unique_ptr<wasmtime::Engine>(new wasmtime::Engine);
+    store = std::unique_ptr<wasmtime::Store>(new wasmtime::Store(*engine));
+}
+
+WasmFunctionManager::~WasmFunctionManager() {
+    engine.reset();
+    store.reset();
+}
+
+bool WasmFunctionManager::RegisterFunction(std::string functionName, 
std::string functionHandler,
+                                           const std::string& watString) {
+    auto funcBody = funcs.find(functionName);
+    if (funcBody != funcs.end()) {
+        return false;
+    }
+    auto wasmRuntime = createInstanceAndFunction(watString, functionHandler);
+    funcs.emplace(functionName, wasmRuntime);
+    return true;
+}
+
+bool WasmFunctionManager::RegisterFunction(std::string functionName, 
std::string functionHandler,
+                                           const wasmtime::Span<uint8_t>& 
wasm) {
+    auto funcBody = funcs.find(functionName);
+    if (funcBody != funcs.end()) {
+        return false;
+    }
+    auto wasmRuntime = createInstanceAndFunction(wasm, functionHandler);
+    funcs.emplace(functionName, wasmRuntime);
+    return true;
+}
+
+WasmtimeRunInstance WasmFunctionManager::createInstanceAndFunction(
+        const std::string& watString, const std::string& functionHandler) {
+    auto module = wasmtime::Module::compile(*engine, watString).unwrap();
+    auto instance = wasmtime::Instance::create(store.get(), module, 
{}).unwrap();
+    auto function_obj = instance.get(store.get(), functionHandler);
+    wasmtime::Func* func = std::get_if<wasmtime::Func>(&*function_obj);
+    return WasmtimeRunInstance(*func, instance);
+}
+
+WasmtimeRunInstance WasmFunctionManager::createInstanceAndFunction(
+        const wasmtime::Span<uint8_t> wasm, const std::string& 
functionHandler) {
+    auto module = wasmtime::Module::compile(*engine, wasm).unwrap();
+    auto instance = wasmtime::Instance::create(store.get(), module, 
{}).unwrap();
+    auto function_obj = instance.get(store.get(), functionHandler);
+    wasmtime::Func* func = std::get_if<wasmtime::Func>(&*function_obj);
+    return WasmtimeRunInstance(*func, instance);
+}
+
+std::vector<wasmtime::Val> WasmFunctionManager::runElemFunc(const std::string 
functionName,
+                                                            
std::vector<wasmtime::Val> args) {
+    auto module = funcs.at(functionName);
+    auto results = module.func.call(store.get(), args).unwrap();
+    return results;
+}
+
+bool WasmFunctionManager::DeleteFunction(std::string functionName) {
+    auto funcBody = funcs.find(functionName);
+    if (funcBody == funcs.end()) {
+        return false;

Review Comment:
   warning: redundant boolean literal in conditional return statement 
[readability-simplify-boolean-expr]
   
   be/src/util/wasm_manager.cpp:80:
   ```diff
   -     if (funcBody == funcs.end()) {
   -         return false;
   -     }
   -     funcs.erase(functionName);
   -     return true;
   +     return !funcBody == funcs.end();
   ```
   



##########
be/src/util/wasm_manager.cpp:
##########
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/wasm_manager.h"
+
+namespace doris {
+
+WasmFunctionManager::WasmFunctionManager() {
+    engine = std::unique_ptr<wasmtime::Engine>(new wasmtime::Engine);
+    store = std::unique_ptr<wasmtime::Store>(new wasmtime::Store(*engine));
+}
+
+WasmFunctionManager::~WasmFunctionManager() {

Review Comment:
   warning: use '= default' to define a trivial destructor 
[modernize-use-equals-default]
   ```cpp
   WasmFunctionManager::~WasmFunctionManager() {
                        ^
   ```
   



##########
be/src/util/wasm_manager.cpp:
##########
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/wasm_manager.h"
+
+namespace doris {
+
+WasmFunctionManager::WasmFunctionManager() {
+    engine = std::unique_ptr<wasmtime::Engine>(new wasmtime::Engine);
+    store = std::unique_ptr<wasmtime::Store>(new wasmtime::Store(*engine));
+}
+
+WasmFunctionManager::~WasmFunctionManager() {
+    engine.reset();
+    store.reset();
+}
+
+bool WasmFunctionManager::RegisterFunction(std::string functionName, 
std::string functionHandler,
+                                           const std::string& watString) {
+    auto funcBody = funcs.find(functionName);
+    if (funcBody != funcs.end()) {
+        return false;
+    }
+    auto wasmRuntime = createInstanceAndFunction(watString, functionHandler);
+    funcs.emplace(functionName, wasmRuntime);
+    return true;
+}
+
+bool WasmFunctionManager::RegisterFunction(std::string functionName, 
std::string functionHandler,
+                                           const wasmtime::Span<uint8_t>& 
wasm) {
+    auto funcBody = funcs.find(functionName);
+    if (funcBody != funcs.end()) {
+        return false;
+    }
+    auto wasmRuntime = createInstanceAndFunction(wasm, functionHandler);
+    funcs.emplace(functionName, wasmRuntime);
+    return true;
+}
+
+WasmtimeRunInstance WasmFunctionManager::createInstanceAndFunction(
+        const std::string& watString, const std::string& functionHandler) {
+    auto module = wasmtime::Module::compile(*engine, watString).unwrap();
+    auto instance = wasmtime::Instance::create(store.get(), module, 
{}).unwrap();
+    auto function_obj = instance.get(store.get(), functionHandler);
+    wasmtime::Func* func = std::get_if<wasmtime::Func>(&*function_obj);
+    return WasmtimeRunInstance(*func, instance);
+}
+
+WasmtimeRunInstance WasmFunctionManager::createInstanceAndFunction(
+        const wasmtime::Span<uint8_t> wasm, const std::string& 
functionHandler) {
+    auto module = wasmtime::Module::compile(*engine, wasm).unwrap();
+    auto instance = wasmtime::Instance::create(store.get(), module, 
{}).unwrap();
+    auto function_obj = instance.get(store.get(), functionHandler);
+    wasmtime::Func* func = std::get_if<wasmtime::Func>(&*function_obj);
+    return WasmtimeRunInstance(*func, instance);
+}
+
+std::vector<wasmtime::Val> WasmFunctionManager::runElemFunc(const std::string 
functionName,
+                                                            
std::vector<wasmtime::Val> args) {
+    auto module = funcs.at(functionName);
+    auto results = module.func.call(store.get(), args).unwrap();
+    return results;
+}
+
+bool WasmFunctionManager::DeleteFunction(std::string functionName) {

Review Comment:
   warning: method 'DeleteFunction' can be made static 
[readability-convert-member-functions-to-static]
   
   be/src/util/wasm_manager.h:61:
   ```diff
   -     bool DeleteFunction(std::string functionName);
   +     static bool DeleteFunction(std::string functionName);
   ```
   



##########
be/src/util/wasm_manager.cpp:
##########
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/wasm_manager.h"
+
+namespace doris {
+
+WasmFunctionManager::WasmFunctionManager() {
+    engine = std::unique_ptr<wasmtime::Engine>(new wasmtime::Engine);
+    store = std::unique_ptr<wasmtime::Store>(new wasmtime::Store(*engine));
+}
+
+WasmFunctionManager::~WasmFunctionManager() {
+    engine.reset();
+    store.reset();
+}
+
+bool WasmFunctionManager::RegisterFunction(std::string functionName, 
std::string functionHandler,
+                                           const std::string& watString) {
+    auto funcBody = funcs.find(functionName);
+    if (funcBody != funcs.end()) {
+        return false;
+    }
+    auto wasmRuntime = createInstanceAndFunction(watString, functionHandler);
+    funcs.emplace(functionName, wasmRuntime);
+    return true;
+}
+
+bool WasmFunctionManager::RegisterFunction(std::string functionName, 
std::string functionHandler,
+                                           const wasmtime::Span<uint8_t>& 
wasm) {
+    auto funcBody = funcs.find(functionName);
+    if (funcBody != funcs.end()) {
+        return false;
+    }
+    auto wasmRuntime = createInstanceAndFunction(wasm, functionHandler);
+    funcs.emplace(functionName, wasmRuntime);
+    return true;
+}
+
+WasmtimeRunInstance WasmFunctionManager::createInstanceAndFunction(
+        const std::string& watString, const std::string& functionHandler) {
+    auto module = wasmtime::Module::compile(*engine, watString).unwrap();
+    auto instance = wasmtime::Instance::create(store.get(), module, 
{}).unwrap();
+    auto function_obj = instance.get(store.get(), functionHandler);
+    wasmtime::Func* func = std::get_if<wasmtime::Func>(&*function_obj);
+    return WasmtimeRunInstance(*func, instance);
+}
+
+WasmtimeRunInstance WasmFunctionManager::createInstanceAndFunction(

Review Comment:
   warning: method 'createInstanceAndFunction' can be made static 
[readability-convert-member-functions-to-static]
   
   ```suggestion
   static WasmtimeRunInstance WasmFunctionManager::createInstanceAndFunction(
   ```
   



##########
be/src/vec/functions/function_wasm.cpp:
##########
@@ -0,0 +1,189 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "vec/functions/function_wasm.h"
+
+#include <brpc/controller.h>
+#include <fmt/format.h>
+
+#include <algorithm>
+#include <memory>
+#include <string>
+#include <utility>
+
+#include "gutil/strings/substitute.h"
+#include "runtime/exec_env.h"
+#include "runtime/user_function_cache.h"
+#include "vec/columns/column.h"
+#include "vec/data_types/data_type.h"
+#include "vec/data_types/serde/data_type_serde.h"
+#include "vec/functions/function.h"
+
+namespace doris::vectorized {
+
+FunctionWasm::FunctionWasm(const TFunction& fn, const DataTypes& 
argument_types,
+                           const DataTypePtr& return_type)
+        : _argument_types(argument_types), _return_type(return_type), _tfn(fn) 
{
+    _is_nullable = false;
+    for (const auto& type : argument_types) {
+        auto argument_type = type;
+        if (type->is_nullable()) {
+            argument_type = remove_nullable(type);
+            _is_nullable = true;
+        }
+        _not_nullable_argument_types.push_back(argument_type);
+    }
+}
+
+Status FunctionWasm::open(FunctionContext* context, 
FunctionContext::FunctionStateScope scope) {
+    if (scope == FunctionContext::FRAGMENT_LOCAL) {
+        string local_location;
+        auto* function_cache = UserFunctionCache::instance();
+        RETURN_IF_ERROR(function_cache->get_watpath(_tfn.id, 
_tfn.hdfs_location, _tfn.checksum,
+                                                    &local_location));
+        std::shared_ptr<WasmFunctionManager> manager = 
std::make_shared<WasmFunctionManager>();
+        context->set_function_state(FunctionContext::THREAD_LOCAL, manager);
+        std::ifstream wat_file;
+        wat_file.open(local_location.c_str());
+        std::stringstream str_stream;
+        str_stream << wat_file.rdbuf();
+        const std::string wasm_body = str_stream.str();
+        manager->RegisterFunction(_tfn.name.function_name, 
_tfn.scalar_fn.symbol, wasm_body);
+    }
+    return Status::OK();
+}
+
+Status FunctionWasm::execute(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,

Review Comment:
   warning: function 'execute' exceeds recommended size/complexity thresholds 
[readability-function-size]
   ```cpp
   Status FunctionWasm::execute(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
                        ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/vec/functions/function_wasm.cpp:69:** 116 lines including 
whitespace and comments (threshold 80)
   ```cpp
   Status FunctionWasm::execute(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
                        ^
   ```
   
   </details>
   



##########
be/test/util/wasm_manager_test.cpp:
##########
@@ -0,0 +1,57 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/wasm_manager.h"

Review Comment:
   warning: 'util/wasm_manager.h' file not found [clang-diagnostic-error]
   ```cpp
   #include "util/wasm_manager.h"
            ^
   ```
   



##########
be/src/vec/functions/function_wasm.h:
##########
@@ -0,0 +1,82 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <fmt/format.h>
+#include <stddef.h>

Review Comment:
   warning: inclusion of deprecated C++ header 'stddef.h'; consider using 
'cstddef' instead [modernize-deprecated-headers]
   
   ```suggestion
   #include <cstddef>
   ```
   



##########
be/test/util/wasm_test.cpp:
##########
@@ -0,0 +1,61 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest-message.h>
+#include <gtest/gtest-test-part.h>
+
+#include <fstream>
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <wasmtime.hh>
+
+#include "gtest/gtest_pred_impl.h"
+#include "testutil/test_util.h"
+
+namespace doris {
+class WasmtimeTest : public ::testing::Test {
+    std::string readFile(const char* name) {

Review Comment:
   warning: method 'readFile' can be made static 
[readability-convert-member-functions-to-static]
   
   ```suggestion
       static std::string readFile(const char* name) {
   ```
   



##########
be/src/util/wasm_manager.h:
##########
@@ -0,0 +1,65 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <cassert>
+#include <fstream>
+#include <iostream>
+#include <limits>
+#include <sstream>
+#include <string>
+#include <unordered_map>
+#include <vector>
+#include <wasmtime.hh>
+
+namespace doris {
+
+struct WasmtimeRunInstance {
+    wasmtime::Func func;
+    wasmtime::Instance instance;
+    WasmtimeRunInstance(const wasmtime::Func& func, const wasmtime::Instance& 
instance)
+            : func(func), instance(instance) {}
+};
+
+class WasmFunctionManager {
+private:
+    // wasmtime
+    std::unique_ptr<wasmtime::Engine> engine;
+    std::unique_ptr<wasmtime::Store> store;
+    std::unordered_map<std::string, WasmtimeRunInstance> funcs;
+
+    WasmFunctionManager(const WasmFunctionManager&);
+    WasmFunctionManager& operator=(const WasmFunctionManager&);
+
+public:
+    WasmFunctionManager();
+    ~WasmFunctionManager();
+    WasmtimeRunInstance createInstanceAndFunction(const std::string& watString,
+                                                  const std::string& 
functionHandler);
+    WasmtimeRunInstance createInstanceAndFunction(const 
wasmtime::Span<uint8_t> wasm,

Review Comment:
   warning: parameter 'wasm' is const-qualified in the function declaration; 
const-qualification of parameters only has an effect in function definitions 
[readability-avoid-const-params-in-decls]
   
   ```suggestion
       WasmtimeRunInstance createInstanceAndFunction(wasmtime::Span<uint8_t> 
wasm,
   ```
   



##########
be/test/util/wasm_test.cpp:
##########
@@ -0,0 +1,61 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest-message.h>

Review Comment:
   warning: 'gtest/gtest-message.h' file not found [clang-diagnostic-error]
   ```cpp
   #include <gtest/gtest-message.h>
            ^
   ```
   



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to