HappenLee commented on code in PR #24504:
URL: https://github.com/apache/doris/pull/24504#discussion_r1463629972


##########
be/src/vec/functions/function_wasm.cpp:
##########
@@ -0,0 +1,199 @@
+// 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));
+        //        ExecEnv::GetInstance()->wasm_function_manager();
+        std::shared_ptr<WasmFunctionManager> manager = 
std::make_shared<WasmFunctionManager>();
+        context->set_function_state(FunctionContext::THREAD_LOCAL, manager);
+        std::ifstream watFile;
+        watFile.open(local_location.c_str());
+        std::stringstream strStream;
+        strStream << watFile.rdbuf();
+        const std::string wasm_body = strStream.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,
+                             size_t result, size_t input_rows_count, bool 
dry_run) {
+    /**
+     * i32, a 32-bit integer (equivalent to C++’s signed long int)
+     * i64, a 64-bit integer (equivalent to C++’s signed long long int)
+     * f32, 32-bit float (equivalent to C++’s float)
+     * f64, 64-bit float (equivalent to C++’s double)
+     */
+    int arg_size = arguments.size();
+    ColumnPtr data_cols[arg_size];
+    auto* manager = reinterpret_cast<WasmFunctionManager*>(
+            context->get_function_state(FunctionContext::THREAD_LOCAL));
+    auto return_type = _return_type;
+    auto result_nullable = return_type->is_nullable();
+    ColumnUInt8::MutablePtr null_map = nullptr;
+
+    if (result_nullable) {
+        return_type = remove_nullable(_return_type);
+        null_map = ColumnUInt8::create(input_rows_count, 0);
+        memset(null_map->get_data().data(), 0, input_rows_count);
+    }
+
+    //    ColumnPtr nested_column = nullptr;

Review Comment:
   if useless or dead code, please remove



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