You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/12/05 15:07:00 UTC

[GitHub] [doris] Yukang-Lian opened a new pull request, #14396: [Feature](function) Support width_bucket function

Yukang-Lian opened a new pull request, #14396:
URL: https://github.com/apache/doris/pull/14396

   # Proposed changes
   
   Issue Number: close #13981 
   
   ## Problem summary
   
   Describe your changes.
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: 
       - [ ] Yes
       - [x] No
       - [ ] I don't know
   2. Has unit tests been added:
       - [ ] Yes
       - [ ] No
       - [x] No Need
   3. Has document been added or modified:
       - [x] Yes
       - [ ] No
       - [ ] No Need
   4. Does it need to update dependencies:
       - [ ] Yes
       - [x] No
   5. Are there any changes that cannot be rolled back:
       - [ ] Yes (If Yes, please explain WHY)
       - [x] No
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
   
   


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


[GitHub] [doris] github-actions[bot] commented on pull request #14396: [Feature](function) Support width_bucket function

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #14396:
URL: https://github.com/apache/doris/pull/14396#issuecomment-1368158306

   clang-tidy review says "All clean, LGTM! :+1:"


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


[GitHub] [doris] github-actions[bot] commented on pull request #14396: [Feature](function) Support width_bucket function

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #14396:
URL: https://github.com/apache/doris/pull/14396#issuecomment-1373125175

   clang-tidy review says "All clean, LGTM! :+1:"


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


[GitHub] [doris] morningman commented on a diff in pull request #14396: [Feature](function) Support width_bucket function

Posted by GitBox <gi...@apache.org>.
morningman commented on code in PR #14396:
URL: https://github.com/apache/doris/pull/14396#discussion_r1027306020


##########
be/src/vec/functions/function_width_bucket.cpp:
##########
@@ -0,0 +1,156 @@
+// 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/columns/columns_number.h"
+#include "vec/data_types/data_type_nullable.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/functions/function.h"
+#include "vec/functions/function_helpers.h"
+#include "vec/functions/simple_function_factory.h"
+
+namespace doris::vectorized {
+class FunctionWidthBucket : public IFunction {
+public:
+    static constexpr auto name = "width_bucket";
+    static FunctionPtr create() { return std::make_shared<FunctionWidthBucket>(); }
+
+    /// Get function name.
+    String get_name() const override { return name; }
+
+    bool is_variadic() const override { return false; }
+
+    size_t get_number_of_arguments() const override { return 4; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
+        if (arguments[0]->is_nullable()) {
+            return make_nullable(std::make_shared<DataTypeInt64>());
+        } else {
+            return std::make_shared<DataTypeInt64>();
+        }
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) override {
+        ColumnPtr expr_ptr =
+                block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        ColumnPtr min_value_ptr =
+                block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
+        ColumnPtr max_value_ptr =
+                block.get_by_position(arguments[2]).column->convert_to_full_column_if_const();
+        ColumnPtr num_buckets_ptr =
+                block.get_by_position(arguments[3]).column->convert_to_full_column_if_const();
+        int64_t num_buckets = num_buckets_ptr->get_int(0);
+
+        auto nested_column_ptr = ColumnInt64::create(input_rows_count, 0);
+        DataTypePtr expr_type = block.get_by_position(arguments[0]).type;
+
+        _execute_by_type(*expr_ptr, *min_value_ptr, *max_value_ptr, num_buckets, *nested_column_ptr,
+                         expr_type);
+
+        WhichDataType which(remove_nullable(expr_type));
+        if (which.is_nullable()) {
+            auto dest_column_ptr =
+                    ColumnNullable::create(std::move(nested_column_ptr),
+                                           ColumnUInt8::create(nested_column_ptr->size(), 0));
+            block.replace_by_position(result, std::move(dest_column_ptr));
+        } else {
+            block.replace_by_position(result, std::move(nested_column_ptr));
+        }
+        return Status::OK();
+    }
+
+private:
+    template <typename ColumnType>
+    void _execute(const IColumn& expr_column, const IColumn& min_value_column,
+                  const IColumn& max_value_column, const int64_t num_buckets,
+                  IColumn& nested_column) {
+        const ColumnType& expr_column_concrete = reinterpret_cast<const ColumnType&>(expr_column);
+        const ColumnType& min_value_column_concrete =
+                reinterpret_cast<const ColumnType&>(min_value_column);
+        const ColumnType& max_value_column_concrete =
+                reinterpret_cast<const ColumnType&>(max_value_column);
+        ColumnInt64& nested_column_concrete = reinterpret_cast<ColumnInt64&>(nested_column);
+
+        auto min_value = min_value_column_concrete.get_data()[0];
+        auto max_value = max_value_column_concrete.get_data()[0];
+
+        size_t input_rows_count = expr_column.size();
+
+        for (size_t i = 0; i < input_rows_count; ++i) {
+            if (expr_column_concrete.get_data()[i] < min_value) {
+                continue;
+            } else if (expr_column_concrete.get_data()[i] >= max_value) {
+                nested_column_concrete.get_data()[i] = num_buckets + 1;
+            } else {
+                if ((max_value - min_value) / num_buckets == 0) {
+                    continue;
+                }
+                nested_column_concrete.get_data()[i] =
+                        (int64_t)(1 + (expr_column_concrete.get_data()[i] - min_value) /
+                                              ((max_value - min_value) / num_buckets));
+            }
+            LOG(WARNING) << std::to_string(i) + "   " +

Review Comment:
   Do not print WARNING log here



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


[GitHub] [doris] zhangstar333 commented on a diff in pull request #14396: [Feature](function) Support width_bucket function

Posted by GitBox <gi...@apache.org>.
zhangstar333 commented on code in PR #14396:
URL: https://github.com/apache/doris/pull/14396#discussion_r1058818860


##########
be/src/vec/functions/function_width_bucket.cpp:
##########
@@ -0,0 +1,154 @@
+// 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/columns/columns_number.h"
+#include "vec/data_types/data_type_nullable.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/functions/function.h"
+#include "vec/functions/function_helpers.h"
+#include "vec/functions/simple_function_factory.h"
+
+namespace doris::vectorized {
+class FunctionWidthBucket : public IFunction {
+public:
+    static constexpr auto name = "width_bucket";
+    static FunctionPtr create() { return std::make_shared<FunctionWidthBucket>(); }
+
+    /// Get function name.
+    String get_name() const override { return name; }
+
+    bool is_variadic() const override { return false; }
+
+    size_t get_number_of_arguments() const override { return 4; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
+        if (arguments[0]->is_nullable()) {
+            return make_nullable(std::make_shared<DataTypeInt64>());
+        } else {
+            return std::make_shared<DataTypeInt64>();
+        }
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) override {
+        ColumnPtr expr_ptr =
+                block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        ColumnPtr min_value_ptr =
+                block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
+        ColumnPtr max_value_ptr =
+                block.get_by_position(arguments[2]).column->convert_to_full_column_if_const();
+        ColumnPtr num_buckets_ptr =
+                block.get_by_position(arguments[3]).column->convert_to_full_column_if_const();
+        int64_t num_buckets = num_buckets_ptr->get_int(0);
+
+        auto nested_column_ptr = ColumnInt64::create(input_rows_count, 0);
+        DataTypePtr expr_type = block.get_by_position(arguments[0]).type;
+
+        _execute_by_type(*expr_ptr, *min_value_ptr, *max_value_ptr, num_buckets, *nested_column_ptr,
+                         expr_type);
+
+        WhichDataType which(remove_nullable(expr_type));
+        if (which.is_nullable()) {

Review Comment:
   see have remove nullable in 64 line? 



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


[GitHub] [doris] dataroaring merged pull request #14396: [Feature](function) Support width_bucket function

Posted by GitBox <gi...@apache.org>.
dataroaring merged PR #14396:
URL: https://github.com/apache/doris/pull/14396


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


[GitHub] [doris] Yukang-Lian closed pull request #14396: [Feature](function) Support width_bucket function

Posted by GitBox <gi...@apache.org>.
Yukang-Lian closed pull request #14396: [Feature](function) Support width_bucket function
URL: https://github.com/apache/doris/pull/14396


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


[GitHub] [doris] hello-stephen commented on pull request #14396: [Feature](function) Support width_bucket function

Posted by GitBox <gi...@apache.org>.
hello-stephen commented on PR #14396:
URL: https://github.com/apache/doris/pull/14396#issuecomment-1319962691

   TeamCity pipeline, clickbench performance test result:
    the sum of best hot time: 34.78 seconds
    load time: 443 seconds
    storage size: 17150166363 Bytes
    https://doris-community-test-1308700295.cos.ap-hongkong.myqcloud.com/tmp/20221118125919_clickbench_pr_48778.html


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


[GitHub] [doris] github-actions[bot] commented on pull request #14396: [Feature](function) Support width_bucket function

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #14396:
URL: https://github.com/apache/doris/pull/14396#issuecomment-1367812493

   clang-tidy review says "All clean, LGTM! :+1:"


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


[GitHub] [doris] github-actions[bot] commented on pull request #14396: [Feature](function) Support width_bucket function

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #14396:
URL: https://github.com/apache/doris/pull/14396#issuecomment-1379852588

   PR approved by at least one committer and no changes requested.


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


[GitHub] [doris] github-actions[bot] commented on pull request #14396: [Feature](function) Support width_bucket function

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #14396:
URL: https://github.com/apache/doris/pull/14396#issuecomment-1377121020

   PR approved by anyone and no changes requested.


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


[GitHub] [doris] morningman commented on a diff in pull request #14396: [Feature](function) Support width_bucket function

Posted by GitBox <gi...@apache.org>.
morningman commented on code in PR #14396:
URL: https://github.com/apache/doris/pull/14396#discussion_r1027305954


##########
docs/zh-CN/docs/sql-manual/sql-functions/width-bucket.md:
##########
@@ -0,0 +1,153 @@
+---
+{
+    "title": "width_bucket",
+    "language": "zh-CN"
+}
+---
+
+<!-- 
+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.
+-->
+
+## width_bucket
+
+### Description
+
+构造等宽直方图,其中直方图范围被划分为相同大小的区间,并在计算后返回表达式的值所在的桶号。该函数返回一个整数值或空值(如果任何输入为空值则返回空值)。
+
+#### Syntax
+
+```sql
+width_bucket(expr, min_value, max_value, num_buckets)
+```
+
+#### Arguments
+`expr` -
+创建直方图的表达式。此表达式必须计算为数值或可隐式转换为数值的值。

Review Comment:
   这里说必须是数值,但是下面的示例中,可以使用 `date` 类型?



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


[GitHub] [doris] Yukang-Lian commented on a diff in pull request #14396: [Feature](function) Support width_bucket function

Posted by GitBox <gi...@apache.org>.
Yukang-Lian commented on code in PR #14396:
URL: https://github.com/apache/doris/pull/14396#discussion_r1027505309


##########
docs/zh-CN/docs/sql-manual/sql-functions/width-bucket.md:
##########
@@ -0,0 +1,153 @@
+---
+{
+    "title": "width_bucket",
+    "language": "zh-CN"
+}
+---
+
+<!-- 
+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.
+-->
+
+## width_bucket
+
+### Description
+
+构造等宽直方图,其中直方图范围被划分为相同大小的区间,并在计算后返回表达式的值所在的桶号。该函数返回一个整数值或空值(如果任何输入为空值则返回空值)。
+
+#### Syntax
+
+```sql
+width_bucket(expr, min_value, max_value, num_buckets)
+```
+
+#### Arguments
+`expr` -
+创建直方图的表达式。此表达式必须计算为数值或可隐式转换为数值的值。

Review Comment:
   `date` can be implicitly converted to a numeric value. Actually, `date` is `Int64`. https://github.com/apache/doris/blob/ff197b0fa537e076ff1a0b5c43437552fb6d8ba1/be/src/vec/core/types.h#L262-L265



##########
be/src/vec/functions/function_width_bucket.cpp:
##########
@@ -0,0 +1,156 @@
+// 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/columns/columns_number.h"
+#include "vec/data_types/data_type_nullable.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/functions/function.h"
+#include "vec/functions/function_helpers.h"
+#include "vec/functions/simple_function_factory.h"
+
+namespace doris::vectorized {
+class FunctionWidthBucket : public IFunction {
+public:
+    static constexpr auto name = "width_bucket";
+    static FunctionPtr create() { return std::make_shared<FunctionWidthBucket>(); }
+
+    /// Get function name.
+    String get_name() const override { return name; }
+
+    bool is_variadic() const override { return false; }
+
+    size_t get_number_of_arguments() const override { return 4; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
+        if (arguments[0]->is_nullable()) {
+            return make_nullable(std::make_shared<DataTypeInt64>());
+        } else {
+            return std::make_shared<DataTypeInt64>();
+        }
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) override {
+        ColumnPtr expr_ptr =
+                block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        ColumnPtr min_value_ptr =
+                block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
+        ColumnPtr max_value_ptr =
+                block.get_by_position(arguments[2]).column->convert_to_full_column_if_const();
+        ColumnPtr num_buckets_ptr =
+                block.get_by_position(arguments[3]).column->convert_to_full_column_if_const();
+        int64_t num_buckets = num_buckets_ptr->get_int(0);
+
+        auto nested_column_ptr = ColumnInt64::create(input_rows_count, 0);
+        DataTypePtr expr_type = block.get_by_position(arguments[0]).type;
+
+        _execute_by_type(*expr_ptr, *min_value_ptr, *max_value_ptr, num_buckets, *nested_column_ptr,
+                         expr_type);
+
+        WhichDataType which(remove_nullable(expr_type));
+        if (which.is_nullable()) {
+            auto dest_column_ptr =
+                    ColumnNullable::create(std::move(nested_column_ptr),
+                                           ColumnUInt8::create(nested_column_ptr->size(), 0));
+            block.replace_by_position(result, std::move(dest_column_ptr));
+        } else {
+            block.replace_by_position(result, std::move(nested_column_ptr));
+        }
+        return Status::OK();
+    }
+
+private:
+    template <typename ColumnType>
+    void _execute(const IColumn& expr_column, const IColumn& min_value_column,
+                  const IColumn& max_value_column, const int64_t num_buckets,
+                  IColumn& nested_column) {
+        const ColumnType& expr_column_concrete = reinterpret_cast<const ColumnType&>(expr_column);
+        const ColumnType& min_value_column_concrete =
+                reinterpret_cast<const ColumnType&>(min_value_column);
+        const ColumnType& max_value_column_concrete =
+                reinterpret_cast<const ColumnType&>(max_value_column);
+        ColumnInt64& nested_column_concrete = reinterpret_cast<ColumnInt64&>(nested_column);
+
+        auto min_value = min_value_column_concrete.get_data()[0];
+        auto max_value = max_value_column_concrete.get_data()[0];
+
+        size_t input_rows_count = expr_column.size();
+
+        for (size_t i = 0; i < input_rows_count; ++i) {
+            if (expr_column_concrete.get_data()[i] < min_value) {
+                continue;
+            } else if (expr_column_concrete.get_data()[i] >= max_value) {
+                nested_column_concrete.get_data()[i] = num_buckets + 1;
+            } else {
+                if ((max_value - min_value) / num_buckets == 0) {
+                    continue;
+                }
+                nested_column_concrete.get_data()[i] =
+                        (int64_t)(1 + (expr_column_concrete.get_data()[i] - min_value) /
+                                              ((max_value - min_value) / num_buckets));
+            }
+            LOG(WARNING) << std::to_string(i) + "   " +

Review Comment:
   This is used for debugging. I forgot to remove it.



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


[GitHub] [doris] github-actions[bot] commented on a diff in pull request #14396: [Feature](function) Support width_bucket function

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on code in PR #14396:
URL: https://github.com/apache/doris/pull/14396#discussion_r1039444924


##########
be/src/vec/functions/function_width_bucket.cpp:
##########
@@ -0,0 +1,154 @@
+// 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/columns/columns_number.h"
+#include "vec/data_types/data_type_nullable.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/functions/function.h"
+#include "vec/functions/function_helpers.h"
+#include "vec/functions/simple_function_factory.h"
+
+namespace doris::vectorized {
+class FunctionWidthBucket : public IFunction {
+public:
+    static constexpr auto name = "width_bucket";
+    static FunctionPtr create() { return std::make_shared<FunctionWidthBucket>(); }
+
+    /// Get function name.
+    String get_name() const override { return name; }
+
+    bool is_variadic() const override { return false; }
+
+    size_t get_number_of_arguments() const override { return 4; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
+        if (arguments[0]->is_nullable()) {
+            return make_nullable(std::make_shared<DataTypeInt64>());
+        } else {
+            return std::make_shared<DataTypeInt64>();
+        }
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,

Review Comment:
   warning: parameter 'context' is unused [misc-unused-parameters]
   
   ```suggestion
       Status execute_impl(FunctionContext*  /*context*/, Block& block, const ColumnNumbers& arguments,
   ```
   



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