You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "niebayes (via GitHub)" <gi...@apache.org> on 2023/06/29 10:00:37 UTC

[GitHub] [doris] niebayes commented on a diff in pull request #21330: support array_contains_all function

niebayes commented on code in PR #21330:
URL: https://github.com/apache/doris/pull/21330#discussion_r1246414334


##########
be/src/vec/functions/array/function_array_contains_all.cpp:
##########
@@ -0,0 +1,160 @@
+// 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 "common/status.h"
+ #include "vec/columns/column.h"
+ #include "vec/columns/column_array.h"
+ #include "vec/columns/column_const.h"
+ #include "vec/columns/column_nullable.h"
+ #include "vec/common/assert_cast.h"
+ #include "vec/core/block.h"
+ #include "vec/core/column_numbers.h"
+ #include "vec/core/types.h"
+ #include "vec/data_types/data_type.h"
+ #include "vec/data_types/data_type_number.h"
+ #include "vec/functions/function.h"
+ #include "vec/functions/simple_function_factory.h"
+
+ namespace doris::vectorized {
+
+ class FunctionArrayContainsAll : public IFunction {
+ public:
+     static constexpr auto name {"array_contains_all"};
+
+     static FunctionPtr create() { return std::make_shared<FunctionArrayContainsAll>(); }
+
+     String get_name() const override { return name; }
+
+     bool use_default_implementation_for_nulls() const override { return false; }
+
+     bool is_variadic() const override { return false; }
+
+     size_t get_number_of_arguments() const override { return 2; }
+
+     DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
+         return std::make_shared<DataTypeUInt8>();
+     }
+
+     Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
+                         size_t result, size_t input_rows_count) override {
+         // construct arrays from the input columns.
+         const Array left_array = from_input_column(block.get_by_position(arguments[0]).column);
+         const Array right_array = from_input_column(block.get_by_position(arguments[1]).column);
+
+         // construct a column to store the execution result.
+         auto result_column = ColumnUInt8::create(input_rows_count);
+         UInt8* result_data = result_column->get_data().data();
+
+         // check if the left array contains all of the right elements.
+         _execute_internal(left_array, right_array, result_data);
+
+         // store the result column in the specified `result` column of the block.
+         block.replace_by_position(result, std::move(result_column));
+
+         return Status::OK();
+     }
+
+ private:
+     // the internal array type.
+     struct Array {

Review Comment:
   `Array` is an aggregate type wrapping array data and the corresponding nullmap. It's used for the sake of code reuse and readability.



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org