This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 59b31a03c4 [Improvement](agg function) support
group_bit_and/group_bit_or/group_bit_xor functions (#14386)
59b31a03c4 is described below
commit 59b31a03c4cfe85addc29a6252735dad7ca19acb
Author: zy-kkk <[email protected]>
AuthorDate: Thu Nov 24 16:46:42 2022 +0800
[Improvement](agg function) support
group_bit_and/group_bit_or/group_bit_xor functions (#14386)
---
be/src/vec/CMakeLists.txt | 1 +
.../aggregate_functions/aggregate_function_bit.cpp | 74 ++++++++++++
.../aggregate_functions/aggregate_function_bit.h | 129 +++++++++++++++++++++
.../aggregate_function_simple_factory.cpp | 2 +
.../aggregate-functions/group_bit_and.md | 60 ++++++++++
.../aggregate-functions/group_bit_or.md | 60 ++++++++++
.../aggregate-functions/group_bit_xor.md | 60 ++++++++++
docs/sidebars.json | 3 +
.../aggregate-functions/group_bit_and.md | 60 ++++++++++
.../aggregate-functions/group_bit_or.md | 60 ++++++++++
.../aggregate-functions/group_bit_xor.md | 60 ++++++++++
.../java/org/apache/doris/catalog/FunctionSet.java | 12 ++
.../aggregate_functions/test_aggregate_bit.out | 40 +++++++
.../aggregate_functions/test_aggregate_bit.groovy | 71 ++++++++++++
14 files changed, 692 insertions(+)
diff --git a/be/src/vec/CMakeLists.txt b/be/src/vec/CMakeLists.txt
index 2c9a3b051a..c3139a0316 100644
--- a/be/src/vec/CMakeLists.txt
+++ b/be/src/vec/CMakeLists.txt
@@ -34,6 +34,7 @@ set(VEC_FILES
aggregate_functions/aggregate_function_null.cpp
aggregate_functions/aggregate_function_uniq.cpp
aggregate_functions/aggregate_function_hll_union_agg.cpp
+ aggregate_functions/aggregate_function_bit.cpp
aggregate_functions/aggregate_function_bitmap.cpp
aggregate_functions/aggregate_function_reader.cpp
aggregate_functions/aggregate_function_window.cpp
diff --git a/be/src/vec/aggregate_functions/aggregate_function_bit.cpp
b/be/src/vec/aggregate_functions/aggregate_function_bit.cpp
new file mode 100644
index 0000000000..8bce17f456
--- /dev/null
+++ b/be/src/vec/aggregate_functions/aggregate_function_bit.cpp
@@ -0,0 +1,74 @@
+// 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.
+// This file is copied from
+//
https://github.com/ClickHouse/ClickHouse/blob/master/src/AggregateFunctions/AggregateFunctionBitwise.cpp
+// and modified by Doris
+
+#include "vec/aggregate_functions/aggregate_function_bit.h"
+
+#include "vec/aggregate_functions/aggregate_function_simple_factory.h"
+
+namespace doris::vectorized {
+
+template <template <typename> class Data>
+AggregateFunctionPtr createAggregateFunctionBitwise(const std::string& name,
+ const DataTypes&
argument_types,
+ const Array& parameters,
+ const bool
result_is_nullable) {
+ if (!argument_types[0]->can_be_used_in_bit_operations()) {
+ LOG(WARNING) << fmt::format("The type " +
argument_types[0]->get_name() +
+ " of argument for aggregate function " +
name +
+ " is illegal, because it cannot be used in
bitwise operations");
+ }
+
+ auto type = argument_types[0].get();
+ if (type->is_nullable()) {
+ type = assert_cast<const
DataTypeNullable*>(type)->get_nested_type().get();
+ }
+
+ WhichDataType which(*type);
+ if (which.is_int8()) {
+ return AggregateFunctionPtr(new AggregateFunctionBitwise<Int8,
Data<Int8>>(argument_types));
+ } else if (which.is_int16()) {
+ return AggregateFunctionPtr(
+ new AggregateFunctionBitwise<Int16,
Data<Int16>>(argument_types));
+ } else if (which.is_int32()) {
+ return AggregateFunctionPtr(
+ new AggregateFunctionBitwise<Int32,
Data<Int32>>(argument_types));
+ } else if (which.is_int64()) {
+ return AggregateFunctionPtr(
+ new AggregateFunctionBitwise<Int64,
Data<Int64>>(argument_types));
+ } else if (which.is_int128()) {
+ return AggregateFunctionPtr(
+ new AggregateFunctionBitwise<Int128,
Data<Int128>>(argument_types));
+ }
+
+ LOG(WARNING) << fmt::format("Illegal type " +
argument_types[0]->get_name() +
+ " of argument for aggregate function " + name);
+ return nullptr;
+}
+
+void register_aggregate_function_bit(AggregateFunctionSimpleFactory& factory) {
+ factory.register_function("group_bit_or",
+
createAggregateFunctionBitwise<AggregateFunctionGroupBitOrData>);
+ factory.register_function("group_bit_and",
+
createAggregateFunctionBitwise<AggregateFunctionGroupBitAndData>);
+ factory.register_function("group_bit_xor",
+
createAggregateFunctionBitwise<AggregateFunctionGroupBitXorData>);
+}
+
+} // namespace doris::vectorized
\ No newline at end of file
diff --git a/be/src/vec/aggregate_functions/aggregate_function_bit.h
b/be/src/vec/aggregate_functions/aggregate_function_bit.h
new file mode 100644
index 0000000000..e7f2456259
--- /dev/null
+++ b/be/src/vec/aggregate_functions/aggregate_function_bit.h
@@ -0,0 +1,129 @@
+// 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.
+// This file is copied from
+//
https://github.com/ClickHouse/ClickHouse/blob/master/src/AggregateFunctions/AggregateFunctionBitwise.h
+// and modified by Doris
+
+#pragma once
+
+#include <vector>
+
+#include "vec/aggregate_functions/aggregate_function.h"
+#include "vec/columns/column_vector.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/io/io_helper.h"
+
+namespace doris::vectorized {
+
+template <typename T>
+struct AggregateFunctionBaseData {
+public:
+ AggregateFunctionBaseData(T init_value) : res_bit(init_value) {}
+ void write(BufferWritable& buf) const { write_binary(res_bit, buf); }
+ void read(BufferReadable& buf) { read_binary(res_bit, buf); }
+ T get() const { return res_bit; }
+
+protected:
+ T res_bit = {};
+};
+
+template <typename T>
+struct AggregateFunctionGroupBitOrData : public AggregateFunctionBaseData<T> {
+public:
+ static constexpr auto name = "group_bit_or";
+ AggregateFunctionGroupBitOrData() : AggregateFunctionBaseData<T>(0) {}
+
+ void add(T value) { AggregateFunctionBaseData<T>::res_bit |= value; }
+
+ void merge(const AggregateFunctionGroupBitOrData<T>& rhs) {
+ AggregateFunctionBaseData<T>::res_bit |= rhs.res_bit;
+ }
+
+ void reset() { AggregateFunctionBaseData<T>::res_bit = 0; }
+};
+
+template <typename T>
+struct AggregateFunctionGroupBitAndData : public AggregateFunctionBaseData<T> {
+public:
+ static constexpr auto name = "group_bit_and";
+ AggregateFunctionGroupBitAndData() : AggregateFunctionBaseData<T>(-1) {}
+
+ void add(T value) { AggregateFunctionBaseData<T>::res_bit &= value; }
+
+ void merge(const AggregateFunctionGroupBitAndData<T>& rhs) {
+ AggregateFunctionBaseData<T>::res_bit &= rhs.res_bit;
+ }
+
+ void reset() { AggregateFunctionBaseData<T>::res_bit = -1; }
+};
+
+template <typename T>
+struct AggregateFunctionGroupBitXorData : public AggregateFunctionBaseData<T> {
+ static constexpr auto name = "group_bit_xor";
+ AggregateFunctionGroupBitXorData() : AggregateFunctionBaseData<T>(0) {}
+
+ void add(T value) { AggregateFunctionBaseData<T>::res_bit ^= value; }
+
+ void merge(const AggregateFunctionGroupBitXorData& rhs) {
+ AggregateFunctionBaseData<T>::res_bit ^= rhs.res_bit;
+ }
+
+ void reset() { AggregateFunctionBaseData<T>::res_bit = 0; }
+};
+
+/// Counts bitwise operation on numbers.
+template <typename T, typename Data>
+class AggregateFunctionBitwise final
+ : public IAggregateFunctionDataHelper<Data,
AggregateFunctionBitwise<T, Data>> {
+public:
+ AggregateFunctionBitwise(const DataTypes& argument_types_)
+ : IAggregateFunctionDataHelper<Data, AggregateFunctionBitwise<T,
Data>>(argument_types_,
+
{}) {}
+
+ String get_name() const override { return Data::name; }
+
+ DataTypePtr get_return_type() const override { return
std::make_shared<DataTypeNumber<T>>(); }
+
+ void add(AggregateDataPtr __restrict place, const IColumn** columns,
size_t row_num,
+ Arena*) const override {
+ const auto& column = static_cast<const ColumnVector<T>&>(*columns[0]);
+ this->data(place).add(column.get_data()[row_num]);
+ }
+
+ void reset(AggregateDataPtr place) const override {
this->data(place).reset(); }
+
+ void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs,
+ Arena*) const override {
+ this->data(place).merge(this->data(rhs));
+ }
+
+ void serialize(ConstAggregateDataPtr __restrict place, BufferWritable&
buf) const override {
+ this->data(place).write(buf);
+ }
+
+ void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf,
+ Arena*) const override {
+ this->data(place).read(buf);
+ }
+
+ void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn&
to) const override {
+ auto& column = static_cast<ColumnVector<T>&>(to);
+ column.get_data().push_back(this->data(place).get());
+ }
+};
+
+} // namespace doris::vectorized
\ No newline at end of file
diff --git
a/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp
b/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp
index c7f8f263dc..8a28ee2f69 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp
+++ b/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp
@@ -37,6 +37,7 @@ void
register_aggregate_function_avg(AggregateFunctionSimpleFactory& factory);
void register_aggregate_function_count(AggregateFunctionSimpleFactory&
factory);
void register_aggregate_function_HLL_union_agg(AggregateFunctionSimpleFactory&
factory);
void register_aggregate_function_uniq(AggregateFunctionSimpleFactory& factory);
+void register_aggregate_function_bit(AggregateFunctionSimpleFactory& factory);
void register_aggregate_function_bitmap(AggregateFunctionSimpleFactory&
factory);
void register_aggregate_function_window_rank(AggregateFunctionSimpleFactory&
factory);
void register_aggregate_function_window_lead_lag_first_last(
@@ -65,6 +66,7 @@ AggregateFunctionSimpleFactory&
AggregateFunctionSimpleFactory::instance() {
register_aggregate_function_avg(instance);
register_aggregate_function_count(instance);
register_aggregate_function_uniq(instance);
+ register_aggregate_function_bit(instance);
register_aggregate_function_bitmap(instance);
register_aggregate_function_combinator_distinct(instance);
register_aggregate_function_reader_load(
diff --git
a/docs/en/docs/sql-manual/sql-functions/aggregate-functions/group_bit_and.md
b/docs/en/docs/sql-manual/sql-functions/aggregate-functions/group_bit_and.md
new file mode 100644
index 0000000000..73c52f3205
--- /dev/null
+++ b/docs/en/docs/sql-manual/sql-functions/aggregate-functions/group_bit_and.md
@@ -0,0 +1,60 @@
+---
+{
+ "title": "group_bit_and",
+ "language": "en"
+}
+---
+
+<!--
+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.
+-->
+
+## group_bit_and
+### description
+#### Syntax
+
+`expr GROUP_BIT_AND(expr)`
+
+Perform an and calculation on expr, and return a new expr.
+All ints are supported
+
+### example
+
+```
+mysql> select * from group_bit;
++-------+
+| value |
++-------+
+| 3 |
+| 1 |
+| 2 |
+| 4 |
++-------+
+4 rows in set (0.02 sec)
+
+mysql> select group_bit_and(value) from group_bit;
++------------------------+
+| group_bit_and(`value`) |
++------------------------+
+| 0 |
++------------------------+
+```
+
+### keywords
+
+ GROUP_BIT_AND,BIT
diff --git
a/docs/en/docs/sql-manual/sql-functions/aggregate-functions/group_bit_or.md
b/docs/en/docs/sql-manual/sql-functions/aggregate-functions/group_bit_or.md
new file mode 100644
index 0000000000..1bbe5387a5
--- /dev/null
+++ b/docs/en/docs/sql-manual/sql-functions/aggregate-functions/group_bit_or.md
@@ -0,0 +1,60 @@
+---
+{
+ "title": "group_bit_or",
+ "language": "en"
+}
+---
+
+<!--
+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.
+-->
+
+## group_bit_or
+### description
+#### Syntax
+
+`expr GROUP_BIT_OR(expr)`
+
+Perform an or calculation on expr, and return a new expr.
+All ints are supported
+
+### example
+
+```
+mysql> select * from group_bit;
++-------+
+| value |
++-------+
+| 3 |
+| 1 |
+| 2 |
+| 4 |
++-------+
+4 rows in set (0.02 sec)
+
+mysql> select group_bit_or(value) from group_bit;
++-----------------------+
+| group_bit_or(`value`) |
++-----------------------+
+| 7 |
++-----------------------+
+```
+
+### keywords
+
+ GROUP_BIT_OR,BIT
diff --git
a/docs/en/docs/sql-manual/sql-functions/aggregate-functions/group_bit_xor.md
b/docs/en/docs/sql-manual/sql-functions/aggregate-functions/group_bit_xor.md
new file mode 100644
index 0000000000..416b1d8b4e
--- /dev/null
+++ b/docs/en/docs/sql-manual/sql-functions/aggregate-functions/group_bit_xor.md
@@ -0,0 +1,60 @@
+---
+{
+ "title": "group_bit_xor",
+ "language": "en"
+}
+---
+
+<!--
+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.
+-->
+
+## group_bit_xor
+### description
+#### Syntax
+
+`expr GROUP_BIT_XOR(expr)`
+
+Perform an xor calculation on expr, and return a new expr.
+All ints are supported
+
+### example
+
+```
+mysql> select * from group_bit;
++-------+
+| value |
++-------+
+| 3 |
+| 1 |
+| 2 |
+| 4 |
++-------+
+4 rows in set (0.02 sec)
+
+mysql> select group_bit_xor(value) from group_bit;
++------------------------+
+| group_bit_xor(`value`) |
++------------------------+
+| 4 |
++------------------------+
+```
+
+### keywords
+
+ GROUP_BIT_XOR,BIT
diff --git a/docs/sidebars.json b/docs/sidebars.json
index 16096c8a40..2ebd3eabab 100644
--- a/docs/sidebars.json
+++ b/docs/sidebars.json
@@ -453,6 +453,9 @@
"sql-manual/sql-functions/aggregate-functions/max_by",
"sql-manual/sql-functions/aggregate-functions/bitmap_union",
"sql-manual/sql-functions/aggregate-functions/group_bitmap_xor",
+
"sql-manual/sql-functions/aggregate-functions/group_bit_and",
+
"sql-manual/sql-functions/aggregate-functions/group_bit_or",
+
"sql-manual/sql-functions/aggregate-functions/group_bit_xor",
"sql-manual/sql-functions/aggregate-functions/percentile_approx",
"sql-manual/sql-functions/aggregate-functions/stddev",
"sql-manual/sql-functions/aggregate-functions/group_concat",
diff --git
a/docs/zh-CN/docs/sql-manual/sql-functions/aggregate-functions/group_bit_and.md
b/docs/zh-CN/docs/sql-manual/sql-functions/aggregate-functions/group_bit_and.md
new file mode 100644
index 0000000000..8ec3d7d86f
--- /dev/null
+++
b/docs/zh-CN/docs/sql-manual/sql-functions/aggregate-functions/group_bit_and.md
@@ -0,0 +1,60 @@
+---
+{
+ "title": "group_bit_and",
+ "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.
+-->
+
+## group_bit_and
+### description
+#### Syntax
+
+`expr GROUP_BIT_AND(expr)`
+
+对expr进行 and 计算, 返回新的expr
+支持所有INT类型
+
+### example
+
+```
+mysql> select * from group_bit;
++-------+
+| value |
++-------+
+| 3 |
+| 1 |
+| 2 |
+| 4 |
++-------+
+4 rows in set (0.02 sec)
+
+mysql> select group_bit_and(value) from group_bit;
++------------------------+
+| group_bit_and(`value`) |
++------------------------+
+| 0 |
++------------------------+
+```
+
+### keywords
+
+ GROUP_BIT_AND,BIT
diff --git
a/docs/zh-CN/docs/sql-manual/sql-functions/aggregate-functions/group_bit_or.md
b/docs/zh-CN/docs/sql-manual/sql-functions/aggregate-functions/group_bit_or.md
new file mode 100644
index 0000000000..e254cef7e9
--- /dev/null
+++
b/docs/zh-CN/docs/sql-manual/sql-functions/aggregate-functions/group_bit_or.md
@@ -0,0 +1,60 @@
+---
+{
+ "title": "group_bit_or",
+ "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.
+-->
+
+## group_bit_or
+### description
+#### Syntax
+
+`expr GROUP_BIT_OR(expr)`
+
+对expr进行 or 计算, 返回新的expr
+支持所有INT类型
+
+### example
+
+```
+mysql> select * from group_bit;
++-------+
+| value |
++-------+
+| 3 |
+| 1 |
+| 2 |
+| 4 |
++-------+
+4 rows in set (0.02 sec)
+
+mysql> select group_bit_or(value) from group_bit;
++-----------------------+
+| group_bit_or(`value`) |
++-----------------------+
+| 7 |
++-----------------------+
+```
+
+### keywords
+
+ GROUP_BIT_OR,BIT
diff --git
a/docs/zh-CN/docs/sql-manual/sql-functions/aggregate-functions/group_bit_xor.md
b/docs/zh-CN/docs/sql-manual/sql-functions/aggregate-functions/group_bit_xor.md
new file mode 100644
index 0000000000..d5ca78c87e
--- /dev/null
+++
b/docs/zh-CN/docs/sql-manual/sql-functions/aggregate-functions/group_bit_xor.md
@@ -0,0 +1,60 @@
+---
+{
+ "title": "group_bit_xor",
+ "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.
+-->
+
+## group_bit_xor
+### description
+#### Syntax
+
+`expr GROUP_BIT_XOR(expr)`
+
+对expr进行 xor 计算, 返回新的expr
+支持所有INT类型
+
+### example
+
+```
+mysql> select * from group_bit;
++-------+
+| value |
++-------+
+| 3 |
+| 1 |
+| 2 |
+| 4 |
++-------+
+4 rows in set (0.02 sec)
+
+mysql> select group_bit_xor(value) from group_bit;
++------------------------+
+| group_bit_xor(`value`) |
++------------------------+
+| 4 |
++------------------------+
+```
+
+### keywords
+
+ GROUP_BIT_XOR,BIT
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java
index 5a3af79237..f0261a3b8e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java
@@ -2479,6 +2479,18 @@ public class FunctionSet<T> {
"",
"",
true, false, true, true));
+ //group_bit_function
+ for (Type t : Type.getIntegerTypes()) {
+ addBuiltin(AggregateFunction.createBuiltin("group_bit_or",
+ Lists.newArrayList(t), t, t, "", "", "", "", "",
+ false, true, false, true));
+ addBuiltin(AggregateFunction.createBuiltin("group_bit_and",
+ Lists.newArrayList(t), t, t, "", "", "", "", "",
+ false, true, false, true));
+ addBuiltin(AggregateFunction.createBuiltin("group_bit_xor",
+ Lists.newArrayList(t), t, t, "", "", "", "", "",
+ false, true, false, true));
+ }
//quantile_state
addBuiltin(AggregateFunction.createBuiltin(QUANTILE_UNION,
Lists.newArrayList(Type.QUANTILE_STATE),
Type.QUANTILE_STATE,
diff --git
a/regression-test/data/query_p0/sql_functions/aggregate_functions/test_aggregate_bit.out
b/regression-test/data/query_p0/sql_functions/aggregate_functions/test_aggregate_bit.out
new file mode 100644
index 0000000000..fd2079225b
--- /dev/null
+++
b/regression-test/data/query_p0/sql_functions/aggregate_functions/test_aggregate_bit.out
@@ -0,0 +1,40 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !select --
+4 4 4 4 4
+
+-- !select --
+127 127 127 127 127
+
+-- !select --
+106 106 106 106 106
+
+-- !select --
+a 12 12 12 12 12
+b 5 5 5 5 5
+
+-- !select --
+a 60 60 60 60 60
+b 95 95 95 95 95
+
+-- !select --
+a 48 48 48 48 48
+b 90 90 90 90 90
+
+-- !select --
+4 4 4 4 4
+
+-- !select --
+-33 -33 -33 -33 -33
+
+-- !select --
+-110 -110 -110 -110 -110
+
+-- !select --
+4 4 4 4 4
+
+-- !select --
+95 95 95 95 95
+
+-- !select --
+70 70 70 70 70
+
diff --git
a/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_bit.groovy
b/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_bit.groovy
new file mode 100644
index 0000000000..1f99a1de86
--- /dev/null
+++
b/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_bit.groovy
@@ -0,0 +1,71 @@
+// 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.
+
+// The cases is copied from https://github.com/trinodb/trino/tree/master
+//
/testing/trino-product-tests/src/main/resources/sql-tests/testcases/aggregate
+// and modified by Doris.
+
+suite("test_aggregate_bit") {
+ sql "set enable_vectorized_engine = true"
+
+ def tableName = "group_bit_test"
+ sql "DROP TABLE IF EXISTS ${tableName}"
+ sql """
+ CREATE TABLE IF NOT EXISTS ${tableName} (
+ flag varchar(10),
+ tint tinyint,
+ sint smallint,
+ `int` int,
+ bint bigint,
+ lint largeint
+ )
+ DISTRIBUTED BY HASH(flag) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1"
+ )
+ """
+
+ //test without null and without group by
+ sql "INSERT INTO ${tableName}
values('a',44,44,44,44,44),('a',28,28,28,28,28),('b',15,15,15,15,15),('b',85,85,85,85,85);"
+
+ qt_select "select
group_bit_and(tint),group_bit_and(sint),group_bit_and(`int`),group_bit_and(bint),group_bit_and(lint)
from ${tableName}"
+ qt_select "select
group_bit_or(tint),group_bit_or(sint),group_bit_or(`int`),group_bit_or(bint),group_bit_or(lint)
from ${tableName}"
+ qt_select "select
group_bit_xor(tint),group_bit_xor(sint),group_bit_xor(`int`),group_bit_xor(bint),group_bit_xor(lint)
from ${tableName}"
+
+ //test without null and with group by
+ qt_select "select flag,
group_bit_and(tint),group_bit_and(sint),group_bit_and(`int`),group_bit_and(bint),group_bit_and(lint)
from ${tableName} group by flag order by flag"
+ qt_select "select flag,
group_bit_or(tint),group_bit_or(sint),group_bit_or(`int`),group_bit_or(bint),group_bit_or(lint)
from ${tableName} group by flag order by flag"
+ qt_select "select flag,
group_bit_xor(tint),group_bit_xor(sint),group_bit_xor(`int`),group_bit_xor(bint),group_bit_xor(lint)
from ${tableName} group by flag order by flag"
+
+ //test with negative number
+ sql "truncate table ${tableName}"
+ sql "INSERT INTO ${tableName}
values('a',-44,-44,-44,-44,-44),('a',28,28,28,28,28),('b',15,15,15,15,15),('b',85,85,85,85,85);"
+
+ qt_select "select
group_bit_and(tint),group_bit_and(sint),group_bit_and(`int`),group_bit_and(bint),group_bit_and(lint)
from ${tableName}"
+ qt_select "select
group_bit_or(tint),group_bit_or(sint),group_bit_or(`int`),group_bit_or(bint),group_bit_or(lint)
from ${tableName}"
+ qt_select "select
group_bit_xor(tint),group_bit_xor(sint),group_bit_xor(`int`),group_bit_xor(bint),group_bit_xor(lint)
from ${tableName}"
+
+ //test with null
+ sql "truncate table ${tableName}"
+ sql "INSERT INTO ${tableName}
values('a',NULL,NULL,NULL,NULL,NULL),('a',28,28,28,28,28),('b',15,15,15,15,15),('b',85,85,85,85,85);"
+
+ qt_select "select
group_bit_and(tint),group_bit_and(sint),group_bit_and(`int`),group_bit_and(bint),group_bit_and(lint)
from ${tableName}"
+ qt_select "select
group_bit_or(tint),group_bit_or(sint),group_bit_or(`int`),group_bit_or(bint),group_bit_or(lint)
from ${tableName}"
+ qt_select "select
group_bit_xor(tint),group_bit_xor(sint),group_bit_xor(`int`),group_bit_xor(bint),group_bit_xor(lint)
from ${tableName}"
+
+ sql "DROP TABLE IF EXISTS ${tableName}"
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]