[Feature] Support bitmap_and_not & bitmap_and_not_count (#6910)
Support bitmap_and_not & bitmap_and_not_count.
This commit is contained in:
@ -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();
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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', ''],
|
||||
|
||||
Reference in New Issue
Block a user