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


##########
be/src/vec/functions/array/function_array_cross_product.cpp:
##########
@@ -0,0 +1,198 @@
+// 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 <gen_cpp/Types_types.h>
+
+#include "common/exception.h"
+#include "common/status.h"
+#include "runtime/primitive_type.h"
+#include "vec/columns/column.h"
+#include "vec/columns/column_array.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/common/assert_cast.h"
+#include "vec/core/types.h"
+#include "vec/data_types/data_type.h"
+#include "vec/data_types/data_type_array.h"
+#include "vec/data_types/data_type_nullable.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/functions/array/function_array_utils.h"
+#include "vec/functions/function.h"
+#include "vec/functions/simple_function_factory.h"
+#include "vec/utils/util.hpp"
+
+namespace doris::vectorized {
+
+class FunctionArrayCrossProduct : public IFunction {
+public:
+    using DataType = PrimitiveTypeTraits<TYPE_DOUBLE>::DataType;
+    using ColumnType = PrimitiveTypeTraits<TYPE_DOUBLE>::ColumnType;
+
+    static constexpr auto name = "cross_product";
+    String get_name() const override { return name; }
+    static FunctionPtr create() { return 
std::make_shared<FunctionArrayCrossProduct>(); }
+    size_t get_number_of_arguments() const override { return 2; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        if (arguments.size() != 2) {
+            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
+                                   "Invalid number of arguments for function 
{}", get_name());
+        }
+
+        if (arguments[0]->get_primitive_type() != TYPE_ARRAY ||
+            arguments[1]->get_primitive_type() != TYPE_ARRAY) {
+            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
+                                   "Arguments for function {} must be arrays", 
get_name());
+        }
+
+        // return ARRAY<DOUBLE>
+        return 
std::make_shared<DataTypeArray>(std::make_shared<DataTypeFloat64>());
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        uint32_t result, size_t input_rows_count) const 
override {
+        const auto& arg1 = block.get_by_position(arguments[0]);
+        const auto& arg2 = block.get_by_position(arguments[1]);
+
+        const IColumn* col1 = arg1.column.get();
+        const IColumn* col2 = arg2.column.get();
+
+        const ColumnConst* col1_const = nullptr;
+        const ColumnConst* col2_const = nullptr;
+
+        if (is_column_const(*col1)) {
+            col1_const = assert_cast<const ColumnConst*>(col1);
+            col1 = &col1_const->get_data_column();
+        }
+        if (is_column_const(*col2)) {
+            col2_const = assert_cast<const ColumnConst*>(col2);
+            col2 = &col2_const->get_data_column();
+        }
+
+        const ColumnArray* arr1 = nullptr;
+        const ColumnArray* arr2 = nullptr;
+
+        if (col1->is_nullable()) {
+            auto nullable1 = assert_cast<const ColumnNullable*>(col1);
+            arr1 = assert_cast<const 
ColumnArray*>(nullable1->get_nested_column_ptr().get());
+        } else {
+            arr1 = assert_cast<const ColumnArray*>(col1);
+        }
+        if (col2->is_nullable()) {
+            auto nullable2 = assert_cast<const ColumnNullable*>(col2);
+            arr2 = assert_cast<const 
ColumnArray*>(nullable2->get_nested_column_ptr().get());
+        } else {
+            arr2 = assert_cast<const ColumnArray*>(col2);
+        }
+
+        const ColumnFloat64* float1 = nullptr;
+        const ColumnFloat64* float2 = nullptr;
+
+        if (arr1->get_data_ptr()->is_nullable()) {
+            if (arr1->get_data_ptr()->has_null()) {
+                return Status::InvalidArgument(
+                        "First argument for function {} cannot have null 
elements", get_name());
+            }
+            auto nullable1 = assert_cast<const 
ColumnNullable*>(arr1->get_data_ptr().get());
+            float1 = assert_cast<const 
ColumnFloat64*>(nullable1->get_nested_column_ptr().get());
+        } else {
+            float1 = assert_cast<const 
ColumnFloat64*>(arr1->get_data_ptr().get());
+        }
+
+        if (arr2->get_data_ptr()->is_nullable()) {
+            if (arr2->get_data_ptr()->has_null()) {
+                return Status::InvalidArgument(
+                        "Second argument for function {} cannot have null 
elements", get_name());
+            }
+            auto nullable2 = assert_cast<const 
ColumnNullable*>(arr2->get_data_ptr().get());
+            float2 = assert_cast<const 
ColumnFloat64*>(nullable2->get_nested_column_ptr().get());

Review Comment:
   should dispose the nullable2 value is null case, it the value is null, the 
float2 maybe have invalid element



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