You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2021/11/01 06:00:17 UTC
[incubator-doris] branch master updated: [Function] add functions
of bitmap_and/or_count (#6912)
This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push:
new 1ff3d70 [Function] add functions of bitmap_and/or_count (#6912)
1ff3d70 is described below
commit 1ff3d708cab1b9e839be002e0b870badf5e99ec5
Author: zhangstar333 <87...@users.noreply.github.com>
AuthorDate: Mon Nov 1 14:00:07 2021 +0800
[Function] add functions of bitmap_and/or_count (#6912)
issue #6875
add bitmap_and_count/ bitmap_or_count
---
be/src/exprs/bitmap_function.cpp | 9 ++++
be/src/exprs/bitmap_function.h | 3 ++
be/test/exprs/bitmap_function_test.cpp | 52 ++++++++++++++++++
docs/.vuepress/sidebar/en.js | 2 +
docs/.vuepress/sidebar/zh-CN.js | 2 +
.../bitmap-functions/bitmap_and_count.md | 63 ++++++++++++++++++++++
.../bitmap-functions/bitmap_or_count.md | 63 ++++++++++++++++++++++
.../bitmap-functions/bitmap_and_count.md | 63 ++++++++++++++++++++++
.../bitmap-functions/bitmap_or_count.md | 63 ++++++++++++++++++++++
gensrc/script/doris_builtins_functions.py | 8 ++-
10 files changed, 327 insertions(+), 1 deletion(-)
diff --git a/be/src/exprs/bitmap_function.cpp b/be/src/exprs/bitmap_function.cpp
index f257664..fe70a48 100644
--- a/be/src/exprs/bitmap_function.cpp
+++ b/be/src/exprs/bitmap_function.cpp
@@ -489,6 +489,15 @@ StringVal BitmapFunctions::bitmap_and(FunctionContext* ctx, const StringVal& lhs
}
return serialize(ctx, &bitmap);
}
+BigIntVal BitmapFunctions::bitmap_and_count(FunctionContext* ctx, const StringVal& lhs,
+ const StringVal& rhs) {
+ return bitmap_count(ctx, bitmap_and(ctx, lhs, rhs));
+}
+
+BigIntVal BitmapFunctions::bitmap_or_count(FunctionContext* ctx, const StringVal& lhs,
+ const StringVal& rhs) {
+ return bitmap_count(ctx, bitmap_or(ctx, lhs, rhs));
+}
StringVal BitmapFunctions::bitmap_xor(FunctionContext* ctx, const StringVal& lhs,
const StringVal& rhs) {
diff --git a/be/src/exprs/bitmap_function.h b/be/src/exprs/bitmap_function.h
index 9c4f155..9143a51 100644
--- a/be/src/exprs/bitmap_function.h
+++ b/be/src/exprs/bitmap_function.h
@@ -59,6 +59,9 @@ public:
const StringVal& dst);
static BigIntVal bitmap_min(FunctionContext* ctx, const StringVal& str);
+ static BigIntVal bitmap_and_count(FunctionContext* ctx, const StringVal& lhs, const StringVal& rhs);
+ static BigIntVal bitmap_or_count(FunctionContext* ctx, const StringVal& lhs, const StringVal& rhs);
+
static StringVal bitmap_serialize(FunctionContext* ctx, const StringVal& src);
static StringVal to_bitmap(FunctionContext* ctx, const StringVal& src);
static StringVal bitmap_hash(FunctionContext* ctx, const StringVal& src);
diff --git a/be/test/exprs/bitmap_function_test.cpp b/be/test/exprs/bitmap_function_test.cpp
index f734e9f..686d2df 100644
--- a/be/test/exprs/bitmap_function_test.cpp
+++ b/be/test/exprs/bitmap_function_test.cpp
@@ -347,6 +347,58 @@ TEST_F(BitmapFunctionsTest, bitmap_and) {
ASSERT_EQ(expected, result);
}
+TEST_F(BitmapFunctionsTest, bitmap_and_count) {
+ BitmapValue bitmap1({0, 1, 2});
+ BitmapValue bitmap2;
+ StringVal bitmap_src1 = convert_bitmap_to_string(ctx, bitmap1);
+ StringVal bitmap_src2 = convert_bitmap_to_string(ctx, bitmap2);
+ BigIntVal result = BitmapFunctions::bitmap_and_count(ctx, bitmap_src1, bitmap_src2);
+ ASSERT_EQ(BigIntVal(0), result);
+
+ result = BitmapFunctions::bitmap_and_count(ctx, bitmap_src1, StringVal::null());
+ ASSERT_EQ(BigIntVal(0), result);
+
+ bitmap1 = BitmapValue({0, 1, 2,std::numeric_limits<uint64_t>::min()});
+ bitmap2 = BitmapValue({0, 1, 2,std::numeric_limits<uint64_t>::max()});
+ bitmap_src1 = convert_bitmap_to_string(ctx, bitmap1);
+ bitmap_src2 = convert_bitmap_to_string(ctx, bitmap2);
+ result = BitmapFunctions::bitmap_and_count(ctx, bitmap_src1, bitmap_src2);
+ ASSERT_EQ(BigIntVal(3), result);
+
+ bitmap1 = BitmapValue({1, 2, 3});
+ bitmap2 = BitmapValue({3, 4, 5});
+ bitmap_src1 = convert_bitmap_to_string(ctx, bitmap1);
+ bitmap_src2 = convert_bitmap_to_string(ctx, bitmap2);
+ result = BitmapFunctions::bitmap_and_count(ctx, bitmap_src1, bitmap_src2);
+ ASSERT_EQ(BigIntVal(1), result);
+}
+
+TEST_F(BitmapFunctionsTest, bitmap_or_count) {
+ BitmapValue bitmap1({0, 1, 2});
+ BitmapValue bitmap2;
+ StringVal bitmap_src1 = convert_bitmap_to_string(ctx, bitmap1);
+ StringVal bitmap_src2 = convert_bitmap_to_string(ctx, bitmap2);
+ BigIntVal result = BitmapFunctions::bitmap_or_count(ctx, bitmap_src1, bitmap_src2);
+ ASSERT_EQ(BigIntVal(3), result);
+
+ result = BitmapFunctions::bitmap_or_count(ctx, bitmap_src1, StringVal::null());
+ ASSERT_EQ(BigIntVal(0), result);
+
+ bitmap1 = BitmapValue({0, 1, 2, std::numeric_limits<uint64_t>::min()});
+ bitmap2 = BitmapValue({0, 1, 2, std::numeric_limits<uint64_t>::max()});
+ bitmap_src1 = convert_bitmap_to_string(ctx, bitmap1);
+ bitmap_src2 = convert_bitmap_to_string(ctx, bitmap2);
+ result = BitmapFunctions::bitmap_or_count(ctx, bitmap_src1, bitmap_src2);
+ ASSERT_EQ(BigIntVal(4), result);
+
+ bitmap1 = BitmapValue({1, 2, 3});
+ bitmap2 = BitmapValue({3, 4, 5});
+ bitmap_src1 = convert_bitmap_to_string(ctx, bitmap1);
+ bitmap_src2 = convert_bitmap_to_string(ctx, bitmap2);
+ result = BitmapFunctions::bitmap_or_count(ctx, bitmap_src1, bitmap_src2);
+ ASSERT_EQ(BigIntVal(5), result);
+}
+
TEST_F(BitmapFunctionsTest, bitmap_not) {
// result is bitmap
BitmapValue bitmap1({1024, 1, 2019});
diff --git a/docs/.vuepress/sidebar/en.js b/docs/.vuepress/sidebar/en.js
index 61120b1..09013ee 100644
--- a/docs/.vuepress/sidebar/en.js
+++ b/docs/.vuepress/sidebar/en.js
@@ -415,6 +415,8 @@ module.exports = [
"bitmap_hash",
"bitmap_intersect",
"bitmap_or",
+ "bitmap_and_count",
+ "bitmap_or_count",
"bitmap_xor",
"bitmap_not",
"bitmap_and_not",
diff --git a/docs/.vuepress/sidebar/zh-CN.js b/docs/.vuepress/sidebar/zh-CN.js
index 99f858c..e0e495d 100644
--- a/docs/.vuepress/sidebar/zh-CN.js
+++ b/docs/.vuepress/sidebar/zh-CN.js
@@ -419,6 +419,8 @@ module.exports = [
"bitmap_hash",
"bitmap_intersect",
"bitmap_or",
+ "bitmap_and_count",
+ "bitmap_or_count",
"bitmap_xor",
"bitmap_not",
"bitmap_and_not",
diff --git a/docs/en/sql-reference/sql-functions/bitmap-functions/bitmap_and_count.md b/docs/en/sql-reference/sql-functions/bitmap-functions/bitmap_and_count.md
new file mode 100644
index 0000000..3736bf3
--- /dev/null
+++ b/docs/en/sql-reference/sql-functions/bitmap-functions/bitmap_and_count.md
@@ -0,0 +1,63 @@
+---
+{
+ "title": "bitmap_and_count",
+ "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.
+-->
+
+# bitmap_and_count
+## description
+### Syntax
+
+`BigIntVal bitmap_and_count(BITMAP lhs, BITMAP rhs)`
+
+Calculate the intersection of two input bitmaps and return the number of intersections.
+
+## example
+
+```
+MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_empty());
++---------------------------------------------------------------+
+| bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_empty()) |
++---------------------------------------------------------------+
+| 0 |
++---------------------------------------------------------------+
+
+
+MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3'));
++----------------------------------------------------------------------------+
+| bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2,3')) |
++----------------------------------------------------------------------------+
+| 3 |
++----------------------------------------------------------------------------+
+
+MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5'));
++----------------------------------------------------------------------------+
+| bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5')) |
++----------------------------------------------------------------------------+
+| 1 |
++----------------------------------------------------------------------------+
+```
+
+## keyword
+
+ BITMAP_AND_COUNT,BITMAP
diff --git a/docs/en/sql-reference/sql-functions/bitmap-functions/bitmap_or_count.md b/docs/en/sql-reference/sql-functions/bitmap-functions/bitmap_or_count.md
new file mode 100644
index 0000000..f296f48
--- /dev/null
+++ b/docs/en/sql-reference/sql-functions/bitmap-functions/bitmap_or_count.md
@@ -0,0 +1,63 @@
+---
+{
+ "title": "bitmap_or_count",
+ "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.
+-->
+
+# bitmap_or_count
+## description
+### Syntax
+
+`BigIntVal bitmap_or_count(BITMAP lhs, BITMAP rhs)`
+
+Calculates the union of two input bitmaps and returns the number of union sets.
+
+## example
+
+```
+MySQL> select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_empty());
++--------------------------------------------------------------+
+| bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_empty()) |
++--------------------------------------------------------------+
+| 3 |
++--------------------------------------------------------------+
+
+
+MySQL> select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3'));
++---------------------------------------------------------------------------+
+| bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2,3')) |
++---------------------------------------------------------------------------+
+| 3 |
++---------------------------------------------------------------------------+
+
+MySQL> select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5'));
++---------------------------------------------------------------------------+
+| bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5')) |
++---------------------------------------------------------------------------+
+| 5 |
++---------------------------------------------------------------------------+
+```
+
+## keyword
+
+ BITMAP_OR_COUNT,BITMAP
diff --git a/docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_and_count.md b/docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_and_count.md
new file mode 100644
index 0000000..3d3fc28
--- /dev/null
+++ b/docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_and_count.md
@@ -0,0 +1,63 @@
+---
+{
+ "title": "bitmap_and_count",
+ "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.
+-->
+
+# bitmap_and_count
+## description
+### Syntax
+
+`BigIntVal bitmap_and_count(BITMAP lhs, BITMAP rhs)`
+
+计算两个输入bitmap的交集,返回交集的个数.
+
+## example
+
+```
+MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_empty());
++---------------------------------------------------------------+
+| bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_empty()) |
++---------------------------------------------------------------+
+| 0 |
++---------------------------------------------------------------+
+
+
+MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3'));
++----------------------------------------------------------------------------+
+| bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2,3')) |
++----------------------------------------------------------------------------+
+| 3 |
++----------------------------------------------------------------------------+
+
+MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5'));
++----------------------------------------------------------------------------+
+| bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5')) |
++----------------------------------------------------------------------------+
+| 1 |
++----------------------------------------------------------------------------+
+```
+
+## keyword
+
+ BITMAP_AND_COUNT,BITMAP
diff --git a/docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_or_count.md b/docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_or_count.md
new file mode 100644
index 0000000..8766d2b
--- /dev/null
+++ b/docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_or_count.md
@@ -0,0 +1,63 @@
+---
+{
+ "title": "bitmap_or_count",
+ "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.
+-->
+
+# bitmap_or_count
+## description
+### Syntax
+
+`BigIntVal bitmap_or_count(BITMAP lhs, BITMAP rhs)`
+
+计算两个输入bitmap的并集,返回并集的个数.
+
+## example
+
+```
+MySQL> select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_empty());
++--------------------------------------------------------------+
+| bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_empty()) |
++--------------------------------------------------------------+
+| 3 |
++--------------------------------------------------------------+
+
+
+MySQL> select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3'));
++---------------------------------------------------------------------------+
+| bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2,3')) |
++---------------------------------------------------------------------------+
+| 3 |
++---------------------------------------------------------------------------+
+
+MySQL> select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5'));
++---------------------------------------------------------------------------+
+| bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5')) |
++---------------------------------------------------------------------------+
+| 5 |
++---------------------------------------------------------------------------+
+```
+
+## keyword
+
+ BITMAP_OR_COUNT,BITMAP
diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py
index eb3270c..fab01d6 100755
--- a/gensrc/script/doris_builtins_functions.py
+++ b/gensrc/script/doris_builtins_functions.py
@@ -1217,7 +1217,13 @@ visible_functions = [
[['bitmap_subset_in_range'], 'BITMAP', ['BITMAP', 'BIGINT', 'BIGINT'],
'_ZN5doris15BitmapFunctions22bitmap_subset_in_rangeEPN9doris_udf15FunctionContextERKNS1_9StringValERKNS1_9BigIntValES9_',
'', '', 'vec', ''],
-
+ [['bitmap_and_count'], 'BIGINT', ['BITMAP','BITMAP'],
+ '_ZN5doris15BitmapFunctions16bitmap_and_countEPN9doris_udf15FunctionContextERKNS1_9StringValES6_',
+ '', '', '', ''],
+ [['bitmap_or_count'], 'BIGINT', ['BITMAP','BITMAP'],
+ '_ZN5doris15BitmapFunctions15bitmap_or_countEPN9doris_udf15FunctionContextERKNS1_9StringValES6_',
+ '', '', '', ''],
+
# hash functions
[['murmur_hash3_32'], 'INT', ['VARCHAR', '...'],
'_ZN5doris13HashFunctions15murmur_hash3_32EPN9doris_udf15FunctionContextEiPKNS1_9StringValE',
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org