This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new 41346f648ce branch-4.1: [fix](be) Restore BOOLEAN support in
linear_histogram #68478 (#68676)
41346f648ce is described below
commit 41346f648ce485f7c006b582edb44ac144fc5384
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Sep 30 21:58:54 2026 +0800
branch-4.1: [fix](be) Restore BOOLEAN support in linear_histogram #68478
(#68676)
Cherry-picked from #68478
Co-authored-by: HappenLee <[email protected]>
---
.../aggregate_function_linear_histogram.cpp | 7 +--
.../exprs/aggregate/agg_linear_histogram_test.cpp | 31 ++++++++++-
.../test_linear_histogram_boolean.out | 17 ++++++
.../test_linear_histogram_boolean.groovy | 63 ++++++++++++++++++++++
4 files changed, 114 insertions(+), 4 deletions(-)
diff --git a/be/src/exprs/aggregate/aggregate_function_linear_histogram.cpp
b/be/src/exprs/aggregate/aggregate_function_linear_histogram.cpp
index 3fcf8a9e288..da004bc34cb 100644
--- a/be/src/exprs/aggregate/aggregate_function_linear_histogram.cpp
+++ b/be/src/exprs/aggregate/aggregate_function_linear_histogram.cpp
@@ -35,9 +35,10 @@ AggregateFunctionPtr
create_aggregate_function_linear_histogram(const std::strin
const
DataTypePtr& result_type,
const bool
result_is_nullable,
const
AggregateFunctionAttr& attr) {
- using creator = creator_with_type_list<TYPE_TINYINT, TYPE_SMALLINT,
TYPE_INT, TYPE_BIGINT,
- TYPE_LARGEINT, TYPE_FLOAT,
TYPE_DOUBLE, TYPE_DECIMAL32,
- TYPE_DECIMAL64, TYPE_DECIMAL128I,
TYPE_DECIMAL256>;
+ using creator =
+ creator_with_type_list<TYPE_BOOLEAN, TYPE_TINYINT, TYPE_SMALLINT,
TYPE_INT, TYPE_BIGINT,
+ TYPE_LARGEINT, TYPE_FLOAT, TYPE_DOUBLE,
TYPE_DECIMAL32,
+ TYPE_DECIMAL64, TYPE_DECIMAL128I,
TYPE_DECIMAL256>;
bool has_offset = (argument_types.size() == 3);
if (has_offset) {
return creator::create<HistogramWithInputParam,
AggregateFunctionLinearHistogramData>(
diff --git a/be/test/exprs/aggregate/agg_linear_histogram_test.cpp
b/be/test/exprs/aggregate/agg_linear_histogram_test.cpp
index 456868b0b52..5064150d660 100644
--- a/be/test/exprs/aggregate/agg_linear_histogram_test.cpp
+++ b/be/test/exprs/aggregate/agg_linear_histogram_test.cpp
@@ -206,7 +206,7 @@ public:
AggregateFunctionSimpleFactory factory =
AggregateFunctionSimpleFactory::instance();
auto agg_function = factory.get("linear_histogram", data_types,
nullptr, false, -1,
{.column_names = {""}});
- EXPECT_NE(agg_function, nullptr);
+ ASSERT_NE(agg_function, nullptr);
std::unique_ptr<char[]> memory(new char[agg_function->size_of_data()]);
AggregateDataPtr place = memory.get();
@@ -256,6 +256,28 @@ public:
EXPECT_EQ(result2, expect_empty_result);
}
+ if (input_rows == 2 && interval == 1 && offset == 0) {
+ EXPECT_EQ(result1,
+ "{\"num_buckets\":2,\"buckets\":["
+
"{\"lower\":0.0,\"upper\":1.0,\"count\":2,\"acc_count\":2},"
+
"{\"lower\":1.0,\"upper\":2.0,\"count\":2,\"acc_count\":4}]}");
+ EXPECT_EQ(result2,
+ "{\"num_buckets\":2,\"buckets\":["
+
"{\"lower\":0.0,\"upper\":1.0,\"count\":1,\"acc_count\":1},"
+
"{\"lower\":1.0,\"upper\":2.0,\"count\":1,\"acc_count\":2}]}");
+ }
+
+ if (input_rows == 2 && interval == 1 && offset == 0.5) {
+ EXPECT_EQ(result1,
+ "{\"num_buckets\":2,\"buckets\":["
+
"{\"lower\":-0.5,\"upper\":0.5,\"count\":2,\"acc_count\":2},"
+
"{\"lower\":0.5,\"upper\":1.5,\"count\":2,\"acc_count\":4}]}");
+ EXPECT_EQ(result2,
+ "{\"num_buckets\":2,\"buckets\":["
+
"{\"lower\":-0.5,\"upper\":0.5,\"count\":1,\"acc_count\":1},"
+
"{\"lower\":0.5,\"upper\":1.5,\"count\":1,\"acc_count\":2}]}");
+ }
+
// test with data
if (input_rows == 100 && interval == 10 && offset == 0) {
std::string expect_result1 = s1;
@@ -290,6 +312,13 @@ private:
Arena _agg_arena_pool;
};
+TEST_F(AggLinearHistogramTest, test_boolean) {
+ test_agg_linear_histogram<DataTypeBool>(0, 1, 0);
+ test_agg_linear_histogram<DataTypeBool>(0, 1, 0.5);
+ test_agg_linear_histogram<DataTypeBool>(2, 1, 0);
+ test_agg_linear_histogram<DataTypeBool>(2, 1, 0.5);
+}
+
TEST_F(AggLinearHistogramTest, test_empty) {
test_agg_linear_histogram<DataTypeInt8>(0, 10, 0);
test_agg_linear_histogram<DataTypeInt16>(0, 10, 0);
diff --git
a/regression-test/data/query_p0/sql_functions/aggregate_functions/test_linear_histogram_boolean.out
b/regression-test/data/query_p0/sql_functions/aggregate_functions/test_linear_histogram_boolean.out
new file mode 100644
index 00000000000..b005daccc5e
--- /dev/null
+++
b/regression-test/data/query_p0/sql_functions/aggregate_functions/test_linear_histogram_boolean.out
@@ -0,0 +1,17 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !nullable --
+{"num_buckets":2,"buckets":[{"lower":0.0,"upper":1.0,"count":1,"acc_count":1},{"lower":1.0,"upper":2.0,"count":2,"acc_count":3}]}
{"num_buckets":2,"buckets":[{"lower":-0.5,"upper":0.5,"count":1,"acc_count":1},{"lower":0.5,"upper":1.5,"count":2,"acc_count":3}]}
+
+-- !not_nullable --
+{"num_buckets":2,"buckets":[{"lower":0.0,"upper":1.0,"count":2,"acc_count":2},{"lower":1.0,"upper":2.0,"count":2,"acc_count":4}]}
{"num_buckets":2,"buckets":[{"lower":-0.5,"upper":0.5,"count":2,"acc_count":2},{"lower":0.5,"upper":1.5,"count":2,"acc_count":4}]}
+
+-- !grouped --
+0
{"num_buckets":1,"buckets":[{"lower":0.0,"upper":1.0,"count":1,"acc_count":1}]}
{"num_buckets":1,"buckets":[{"lower":-0.5,"upper":0.5,"count":1,"acc_count":1}]}
+1
{"num_buckets":1,"buckets":[{"lower":1.0,"upper":2.0,"count":2,"acc_count":2}]}
{"num_buckets":1,"buckets":[{"lower":0.5,"upper":1.5,"count":2,"acc_count":2}]}
+
+-- !all_null --
+{"num_buckets":0,"buckets":[]} {"num_buckets":0,"buckets":[]}
+
+-- !empty --
+{"num_buckets":0,"buckets":[]} {"num_buckets":0,"buckets":[]}
+
diff --git
a/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_linear_histogram_boolean.groovy
b/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_linear_histogram_boolean.groovy
new file mode 100644
index 00000000000..99a936b33e4
--- /dev/null
+++
b/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_linear_histogram_boolean.groovy
@@ -0,0 +1,63 @@
+// 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.
+
+suite("test_linear_histogram_boolean") {
+ sql "DROP TABLE IF EXISTS linear_histogram_boolean"
+ sql """
+ CREATE TABLE linear_histogram_boolean (
+ id INT NOT NULL,
+ b BOOLEAN NULL,
+ non_null_b BOOLEAN NOT NULL
+ )
+ DISTRIBUTED BY HASH(id) BUCKETS 3
+ PROPERTIES ("replication_num" = "1")
+ """
+ sql """
+ INSERT INTO linear_histogram_boolean VALUES
+ (1, TRUE, TRUE), (2, FALSE, FALSE), (3, TRUE, TRUE), (4, NULL,
FALSE)
+ """
+
+ order_qt_nullable """
+ SELECT linear_histogram(b, 1.0), linear_histogram(b, 1.0, 0.5)
+ FROM linear_histogram_boolean
+ """
+ order_qt_not_nullable """
+ SELECT linear_histogram(non_null_b, 1.0), linear_histogram(non_null_b,
1.0, 0.5)
+ FROM linear_histogram_boolean
+ """
+ order_qt_grouped """
+ SELECT id % 2, linear_histogram(b, 1.0), linear_histogram(b, 1.0, 0.5)
+ FROM linear_histogram_boolean GROUP BY id % 2
+ """
+ order_qt_all_null """
+ SELECT linear_histogram(b, 1.0), linear_histogram(b, 1.0, 0.5)
+ FROM linear_histogram_boolean WHERE b IS NULL
+ """
+ order_qt_empty """
+ SELECT linear_histogram(b, 1.0), linear_histogram(b, 1.0, 0.5)
+ FROM linear_histogram_boolean WHERE id < 0
+ """
+
+ test {
+ sql "SELECT linear_histogram(non_null_b, 0.0) FROM
linear_histogram_boolean"
+ exception "interval should be larger than 0"
+ }
+ test {
+ sql "SELECT linear_histogram(non_null_b, 1.0, 1.0) FROM
linear_histogram_boolean"
+ exception "offset should be in [0, interval)"
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]