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 2803029  [Feature] Support bitmap_and_not & bitmap_and_not_count 
(#6910)
2803029 is described below

commit 28030294f707785249ff4932c9ea91cbdf5e88ec
Author: Pxl <952130...@qq.com>
AuthorDate: Mon Nov 1 10:11:54 2021 +0800

    [Feature] Support bitmap_and_not & bitmap_and_not_count (#6910)
    
    Support bitmap_and_not & bitmap_and_not_count.
---
 be/src/exprs/bitmap_function.cpp                   | 10 +++
 be/src/exprs/bitmap_function.h                     |  5 ++
 be/test/exprs/bitmap_function_test.cpp             | 81 ++++++++++++++++++++++
 docs/.vuepress/sidebar/en.js                       |  2 +
 docs/.vuepress/sidebar/zh-CN.js                    |  2 +
 .../bitmap-functions/bitmap_and_not.md             | 48 +++++++++++++
 .../bitmap-functions/bitmap_and_not_count.md       | 49 +++++++++++++
 .../bitmap-functions/bitmap_and_not.md             | 48 +++++++++++++
 .../bitmap-functions/bitmap_and_not_count.md       | 48 +++++++++++++
 gensrc/script/doris_builtins_functions.py          |  6 ++
 10 files changed, 299 insertions(+)

diff --git a/be/src/exprs/bitmap_function.cpp b/be/src/exprs/bitmap_function.cpp
index 5566109..7d03984 100644
--- a/be/src/exprs/bitmap_function.cpp
+++ b/be/src/exprs/bitmap_function.cpp
@@ -530,6 +530,16 @@ StringVal BitmapFunctions::bitmap_not(FunctionContext* 
ctx, const StringVal& lhs
     return serialize(ctx, &bitmap);
 }
 
+StringVal BitmapFunctions::bitmap_and_not(FunctionContext* ctx, const 
StringVal& lhs,
+                                          const StringVal& rhs) {
+    return bitmap_xor(ctx, lhs, bitmap_and(ctx, lhs, rhs));
+}
+
+BigIntVal BitmapFunctions::bitmap_and_not_count(FunctionContext* ctx, const 
StringVal& lhs,
+                                          const StringVal& rhs) {
+    return bitmap_count(ctx, bitmap_and_not(ctx, lhs, rhs));
+}
+
 StringVal BitmapFunctions::bitmap_to_string(FunctionContext* ctx, const 
StringVal& input) {
     if (input.is_null) {
         return StringVal::null();
diff --git a/be/src/exprs/bitmap_function.h b/be/src/exprs/bitmap_function.h
index 5aca41f..a07af1c 100644
--- a/be/src/exprs/bitmap_function.h
+++ b/be/src/exprs/bitmap_function.h
@@ -55,6 +55,8 @@ public:
     static void nullable_bitmap_init(FunctionContext* ctx, StringVal* dst);
     static void bitmap_intersect(FunctionContext* ctx, const StringVal& src, 
StringVal* dst);
     static BigIntVal bitmap_count(FunctionContext* ctx, const StringVal& src);
+    static BigIntVal bitmap_and_not_count(FunctionContext* ctx, const 
StringVal& src,
+                                          const StringVal& dst);
     static BigIntVal bitmap_min(FunctionContext* ctx, const StringVal& str);
 
     static StringVal bitmap_serialize(FunctionContext* ctx, const StringVal& 
src);
@@ -64,6 +66,9 @@ public:
     static StringVal bitmap_xor(FunctionContext* ctx, const StringVal& src, 
const StringVal& dst);
     static StringVal bitmap_and(FunctionContext* ctx, const StringVal& src, 
const StringVal& dst);
     static StringVal bitmap_not(FunctionContext* ctx, const StringVal& src, 
const StringVal& dst);
+    static StringVal bitmap_and_not(FunctionContext* ctx, const StringVal& src,
+                                    const StringVal& dst);
+
     static StringVal bitmap_to_string(FunctionContext* ctx, const StringVal& 
input);
     // Convert a comma separated string to a Bitmap
     // Example:
diff --git a/be/test/exprs/bitmap_function_test.cpp 
b/be/test/exprs/bitmap_function_test.cpp
index 98bae2a..a4e2fb8 100644
--- a/be/test/exprs/bitmap_function_test.cpp
+++ b/be/test/exprs/bitmap_function_test.cpp
@@ -394,6 +394,87 @@ TEST_F(BitmapFunctionsTest, bitmap_not) {
     ASSERT_EQ(expected, result);
 }
 
+TEST_F(BitmapFunctionsTest, bitmap_and_not) {
+    {
+        BitmapValue bitmap1({1, 2, 3});
+        BitmapValue bitmap2({3, 4, 5});
+
+        StringVal bitmap_src = convert_bitmap_to_string(ctx, bitmap1);
+        StringVal bitmap_dst = convert_bitmap_to_string(ctx, bitmap2);
+
+        StringVal bitmap_str = BitmapFunctions::bitmap_and_not(ctx, 
bitmap_src, bitmap_dst);
+        BigIntVal result = BitmapFunctions::bitmap_count(ctx, bitmap_str);
+
+        BigIntVal expected(2);
+        ASSERT_EQ(expected, result);
+    }
+    {
+        BitmapValue bitmap1({1, 2, 3});
+        BitmapValue bitmap2({3, 2, 1});
+
+        StringVal bitmap_src = convert_bitmap_to_string(ctx, bitmap1);
+        StringVal bitmap_dst = convert_bitmap_to_string(ctx, bitmap2);
+
+        StringVal bitmap_str = BitmapFunctions::bitmap_and_not(ctx, 
bitmap_src, bitmap_dst);
+        BigIntVal result = BitmapFunctions::bitmap_count(ctx, bitmap_str);
+
+        BigIntVal expected(0);
+        ASSERT_EQ(expected, result);
+    }
+    {
+        BitmapValue bitmap1({1, 2, 3});
+        BitmapValue bitmap2({998, 999, 1000});
+
+        StringVal bitmap_src = convert_bitmap_to_string(ctx, bitmap1);
+        StringVal bitmap_dst = convert_bitmap_to_string(ctx, bitmap2);
+
+        StringVal bitmap_str = BitmapFunctions::bitmap_and_not(ctx, 
bitmap_src, bitmap_dst);
+        BigIntVal result = BitmapFunctions::bitmap_count(ctx, bitmap_str);
+
+        BigIntVal expected(3);
+        ASSERT_EQ(expected, result);
+    }
+}
+
+TEST_F(BitmapFunctionsTest, bitmap_and_not_count) {
+    {
+        BitmapValue bitmap1({1, 2, 3});
+        BitmapValue bitmap2({3, 4, 5});
+
+        StringVal bitmap_src = convert_bitmap_to_string(ctx, bitmap1);
+        StringVal bitmap_dst = convert_bitmap_to_string(ctx, bitmap2);
+
+        BigIntVal result = BitmapFunctions::bitmap_and_not_count(ctx, 
bitmap_src, bitmap_dst);
+
+        BigIntVal expected(2);
+        ASSERT_EQ(expected, result);
+    }
+    {
+        BitmapValue bitmap1({1, 2, 3});
+        BitmapValue bitmap2({3, 2, 1});
+
+        StringVal bitmap_src = convert_bitmap_to_string(ctx, bitmap1);
+        StringVal bitmap_dst = convert_bitmap_to_string(ctx, bitmap2);
+
+        BigIntVal result = BitmapFunctions::bitmap_and_not_count(ctx, 
bitmap_src, bitmap_dst);
+
+        BigIntVal expected(0);
+        ASSERT_EQ(expected, result);
+    }
+    {
+        BitmapValue bitmap1({1, 2, 3});
+        BitmapValue bitmap2({998, 999, 1000});
+
+        StringVal bitmap_src = convert_bitmap_to_string(ctx, bitmap1);
+        StringVal bitmap_dst = convert_bitmap_to_string(ctx, bitmap2);
+
+        BigIntVal result = BitmapFunctions::bitmap_and_not_count(ctx, 
bitmap_src, bitmap_dst);
+
+        BigIntVal expected(3);
+        ASSERT_EQ(expected, result);
+    }
+}
+
 TEST_F(BitmapFunctionsTest, bitmap_contains) {
     BitmapValue bitmap({4, 5});
     StringVal bitmap_str = convert_bitmap_to_string(ctx, bitmap);
diff --git a/docs/.vuepress/sidebar/en.js b/docs/.vuepress/sidebar/en.js
index 3d82689..8ddd4f6 100644
--- a/docs/.vuepress/sidebar/en.js
+++ b/docs/.vuepress/sidebar/en.js
@@ -416,6 +416,8 @@ module.exports = [
               "bitmap_or",
               "bitmap_xor",
               "bitmap_not",
+              "bitmap_and_not",
+              "bitmap_and_not_count",
               "bitmap_to_string",
               "bitmap_union",
               "bitmap_xor",
diff --git a/docs/.vuepress/sidebar/zh-CN.js b/docs/.vuepress/sidebar/zh-CN.js
index d482ea9..67530d4 100644
--- a/docs/.vuepress/sidebar/zh-CN.js
+++ b/docs/.vuepress/sidebar/zh-CN.js
@@ -420,6 +420,8 @@ module.exports = [
               "bitmap_or",
               "bitmap_xor",
               "bitmap_not",
+              "bitmap_and_not",
+              "bitmap_and_not_count",
               "bitmap_to_string",
               "bitmap_union",
               "bitmap_xor",
diff --git 
a/docs/en/sql-reference/sql-functions/bitmap-functions/bitmap_and_not.md 
b/docs/en/sql-reference/sql-functions/bitmap-functions/bitmap_and_not.md
new file mode 100644
index 0000000..2f11d4b
--- /dev/null
+++ b/docs/en/sql-reference/sql-functions/bitmap-functions/bitmap_and_not.md
@@ -0,0 +1,48 @@
+---
+{
+    "title": "bitmap_and_not",
+    "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_not
+## description
+### Syntax
+
+`BITMAP BITMAP_AND_NOT(BITMAP lhs, BITMAP rhs)`
+
+Calculate the set after lhs minus intersection of two input bitmaps, return 
the new bitmap.
+
+## example
+
+```
+mysql> select 
bitmap_count(bitmap_and_not(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')))
 cnt;
++------+
+| cnt  |
++------+
+|    2 |
++------+
+```
+
+## keyword
+
+    BITMAP_AND_NOT,BITMAP
diff --git 
a/docs/en/sql-reference/sql-functions/bitmap-functions/bitmap_and_not_count.md 
b/docs/en/sql-reference/sql-functions/bitmap-functions/bitmap_and_not_count.md
new file mode 100644
index 0000000..af33d09
--- /dev/null
+++ 
b/docs/en/sql-reference/sql-functions/bitmap-functions/bitmap_and_not_count.md
@@ -0,0 +1,49 @@
+---
+{
+    "title": "bitmap_and_not_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_not_count
+## description
+### Syntax
+
+`BITMAP BITMAP_AND_NOT_COUNT(BITMAP lhs, BITMAP rhs)`
+
+Calculate the set after lhs minus intersection of two input bitmaps, return 
the new bitmap size.
+
+
+## example
+
+```
+mysql> select 
bitmap_and_not_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) 
cnt;
++------+
+| cnt  |
++------+
+|    2 |
++------+
+```
+
+## keyword
+
+    BITMAP_AND_NOT_COUNT,BITMAP
diff --git 
a/docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_and_not.md 
b/docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_and_not.md
new file mode 100644
index 0000000..7074d19
--- /dev/null
+++ b/docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_and_not.md
@@ -0,0 +1,48 @@
+---
+{
+    "title": "bitmap_and_not",
+    "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_not
+## description
+### Syntax
+
+`BITMAP BITMAP_AND_NOT(BITMAP lhs, BITMAP rhs)`
+
+将两个bitmap进行与非操作并返回计算结果。
+
+## example
+
+```
+mysql> select 
bitmap_count(bitmap_and_not(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')))
 cnt;
++------+
+| cnt  |
++------+
+|    2 |
++------+
+```
+
+## keyword
+
+    BITMAP_AND_NOT,BITMAP
diff --git 
a/docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_and_not_count.md
 
b/docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_and_not_count.md
new file mode 100644
index 0000000..509d01a
--- /dev/null
+++ 
b/docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_and_not_count.md
@@ -0,0 +1,48 @@
+---
+{
+    "title": "bitmap_and_not_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_not_count
+## description
+### Syntax
+
+`BITMAP BITMAP_AND_NOT_COUNT(BITMAP lhs, BITMAP rhs)`
+
+将两个bitmap进行与非操作并返回计算返回的大小.
+
+## example
+
+```
+mysql> select 
bitmap_and_not_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) 
cnt;
++------+
+| cnt  |
++------+
+|    2 |
++------+
+```
+
+## keyword
+
+    BITMAP_AND_NOT_COUNT,BITMAP
diff --git a/gensrc/script/doris_builtins_functions.py 
b/gensrc/script/doris_builtins_functions.py
index 89ef431..c67ef16 100755
--- a/gensrc/script/doris_builtins_functions.py
+++ b/gensrc/script/doris_builtins_functions.py
@@ -1169,6 +1169,9 @@ visible_functions = [
     [['bitmap_count'], 'BIGINT', ['BITMAP'],
         
'_ZN5doris15BitmapFunctions12bitmap_countEPN9doris_udf15FunctionContextERKNS1_9StringValE',
         '', '', 'vec', ''],
+    [['bitmap_and_not_count'], 'BIGINT', ['BITMAP','BITMAP'],
+        
'_ZN5doris15BitmapFunctions20bitmap_and_not_countEPN9doris_udf15FunctionContextERKNS1_9StringValES6_',
+        '', '', '', ''],
     [['bitmap_empty'], 'BITMAP', [],
         
'_ZN5doris15BitmapFunctions12bitmap_emptyEPN9doris_udf15FunctionContextE',
         '', '', 'vec', 'ALWAYS_NOT_NULLABLE'],
@@ -1184,6 +1187,9 @@ visible_functions = [
     [['bitmap_and'], 'BITMAP', ['BITMAP','BITMAP'],
         
'_ZN5doris15BitmapFunctions10bitmap_andEPN9doris_udf15FunctionContextERKNS1_9StringValES6_',
         '', '', 'vec', ''],
+    [['bitmap_and_not'], 'BITMAP', ['BITMAP','BITMAP'],
+        
'_ZN5doris15BitmapFunctions14bitmap_and_notEPN9doris_udf15FunctionContextERKNS1_9StringValES6_',
+        '', '', '', ''],
     [['bitmap_to_string'], 'VARCHAR', ['BITMAP'],
         
'_ZN5doris15BitmapFunctions16bitmap_to_stringEPN9doris_udf15FunctionContextERKNS1_9StringValE',
         '', '', 'vec', ''],

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

Reply via email to