[Function] add BE bitmap function bitmap_max (#6942)
Support bitmap_max.
This commit is contained in:
@ -597,6 +597,19 @@ BooleanVal BitmapFunctions::bitmap_has_any(FunctionContext* ctx, const StringVal
|
||||
return {bitmap.cardinality() != 0};
|
||||
}
|
||||
|
||||
BigIntVal BitmapFunctions::bitmap_max(FunctionContext* ctx, const StringVal& src) {
|
||||
if (src.is_null) {
|
||||
return BigIntVal::null();
|
||||
}
|
||||
|
||||
if (src.len == 0) {
|
||||
return reinterpret_cast<BitmapValue*>(src.ptr)->maximum();
|
||||
} else {
|
||||
auto bitmap = BitmapValue((char*)src.ptr);
|
||||
return bitmap.maximum();
|
||||
}
|
||||
}
|
||||
|
||||
template void BitmapFunctions::bitmap_update_int<TinyIntVal>(FunctionContext* ctx,
|
||||
const TinyIntVal& src, StringVal* dst);
|
||||
template void BitmapFunctions::bitmap_update_int<SmallIntVal>(FunctionContext* ctx,
|
||||
|
||||
@ -91,6 +91,7 @@ public:
|
||||
static StringVal bitmap_intersect_serialize(FunctionContext* ctx, const StringVal& src);
|
||||
template <typename T>
|
||||
static BigIntVal bitmap_intersect_finalize(FunctionContext* ctx, const StringVal& src);
|
||||
static BigIntVal bitmap_max(FunctionContext* ctx, const StringVal& str);
|
||||
};
|
||||
} // namespace doris
|
||||
#endif //DORIS_BE_SRC_QUERY_EXPRS_BITMAP_FUNCTION_H
|
||||
|
||||
@ -1439,6 +1439,18 @@ public:
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
doris_udf::BigIntVal maximum() {
|
||||
switch (_type) {
|
||||
case SINGLE:
|
||||
return doris_udf::BigIntVal(_sv);
|
||||
case BITMAP:
|
||||
return doris_udf::BigIntVal(_bitmap.maximum());
|
||||
default:
|
||||
return doris_udf::BigIntVal::null();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void _convert_to_smaller_type() {
|
||||
if (_type == BITMAP) {
|
||||
|
||||
@ -446,6 +446,32 @@ TEST_F(BitmapFunctionsTest, bitmap_from_string) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(BitmapFunctionsTest, bitmap_max) {
|
||||
BigIntVal result = BitmapFunctions::bitmap_max(ctx, StringVal::null());
|
||||
ASSERT_TRUE(result.is_null);
|
||||
|
||||
BitmapValue bitmap1;
|
||||
StringVal empty_str = convert_bitmap_to_string(ctx, bitmap1);
|
||||
result = BitmapFunctions::bitmap_max(ctx, empty_str);
|
||||
ASSERT_TRUE(result.is_null);
|
||||
|
||||
BitmapValue bitmap2 = BitmapValue(1024);
|
||||
StringVal bitmap_str = convert_bitmap_to_string(ctx, bitmap2);
|
||||
result = BitmapFunctions::bitmap_max(ctx, bitmap_str);
|
||||
ASSERT_EQ(BigIntVal(1024), result);
|
||||
|
||||
BitmapValue bitmap3 = BitmapValue({1024, 1});
|
||||
bitmap_str = convert_bitmap_to_string(ctx, bitmap3);
|
||||
result = BitmapFunctions::bitmap_max(ctx, bitmap_str);
|
||||
ASSERT_EQ(BigIntVal(1024), result);
|
||||
|
||||
BitmapValue bitmap4 = BitmapValue({1024, 3, 2});
|
||||
bitmap_str = convert_bitmap_to_string(ctx, bitmap4);
|
||||
result = BitmapFunctions::bitmap_max(ctx, bitmap_str);
|
||||
ASSERT_EQ(BigIntVal(1024), result);
|
||||
}
|
||||
|
||||
|
||||
} // namespace doris
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
@ -420,6 +420,7 @@ module.exports = [
|
||||
"bitmap_union",
|
||||
"bitmap_xor",
|
||||
"to_bitmap",
|
||||
"bitmap_max",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@ -424,6 +424,7 @@ module.exports = [
|
||||
"bitmap_union",
|
||||
"bitmap_xor",
|
||||
"to_bitmap",
|
||||
"bitmap_max",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_max",
|
||||
"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_max
|
||||
## description
|
||||
### Syntax
|
||||
|
||||
`BIGINT BITMAP_MAX(BITMAP input)`
|
||||
|
||||
Calculate and return the max values of a bitmap.
|
||||
|
||||
## example
|
||||
|
||||
```
|
||||
mysql> select bitmap_max(bitmap_from_string('')) value;
|
||||
+-------+
|
||||
| value |
|
||||
+-------+
|
||||
| NULL |
|
||||
+-------+
|
||||
|
||||
mysql> select bitmap_max(bitmap_from_string('1,9999999999')) value;
|
||||
+------------+
|
||||
| value |
|
||||
+------------+
|
||||
| 9999999999 |
|
||||
+------------+
|
||||
```
|
||||
|
||||
## keyword
|
||||
|
||||
BITMAP_MAX,BITMAP
|
||||
@ -0,0 +1,55 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_max",
|
||||
"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_max
|
||||
## description
|
||||
### Syntax
|
||||
|
||||
`BIGINT BITMAP_MAX(BITMAP input)`
|
||||
|
||||
计算并返回 bitmap 中的最大值.
|
||||
|
||||
## example
|
||||
|
||||
```
|
||||
mysql> select bitmap_max(bitmap_from_string('')) value;
|
||||
+-------+
|
||||
| value |
|
||||
+-------+
|
||||
| NULL |
|
||||
+-------+
|
||||
|
||||
mysql> select bitmap_max(bitmap_from_string('1,9999999999')) value;
|
||||
+------------+
|
||||
| value |
|
||||
+------------+
|
||||
| 9999999999 |
|
||||
+------------+
|
||||
```
|
||||
|
||||
## keyword
|
||||
|
||||
BITMAP_MAX,BITMAP
|
||||
@ -1202,6 +1202,9 @@ visible_functions = [
|
||||
[['bitmap_min'], 'BIGINT', ['BITMAP'],
|
||||
'_ZN5doris15BitmapFunctions10bitmap_minEPN9doris_udf15FunctionContextERKNS1_9StringValE',
|
||||
'', '', 'vec', ''],
|
||||
[['bitmap_max'], 'BIGINT', ['BITMAP'],
|
||||
'_ZN5doris15BitmapFunctions10bitmap_maxEPN9doris_udf15FunctionContextERKNS1_9StringValE',
|
||||
'', '', '', ''],
|
||||
|
||||
# hash functions
|
||||
[['murmur_hash3_32'], 'INT', ['VARCHAR', '...'],
|
||||
|
||||
Reference in New Issue
Block a user