morningman commented on a change in pull request #6917:
URL: https://github.com/apache/incubator-doris/pull/6917#discussion_r734949372
##########
File path: be/src/util/bitmap_value.h
##########
@@ -1439,6 +1439,29 @@ class BitmapValue {
return ss.str();
}
+ /**
+ * Return new set with specified range (not include the range_end)
+ */
+ int32_t sub_range(const int32_t& range_start, const int32_t& range_end,
BitmapValue& ret_bitmap) {
+ int32_t count = 0;
Review comment:
```suggestion
int64_t count = 0;
```
##########
File path:
docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_subset_in_range.md
##########
@@ -0,0 +1,57 @@
+---
+{
+ "title": "bitmap_subset_in_range",
+ "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_subset_in_range
+
+## Description
+
+### Syntax
+
+`BITMAP BITMAP_SUBSET_IN_RANGE(BITMAP src, INT range_start, INT range_end)`
+
+返回 BITMAP 指定范围内的子集(不包括范围结束)。
+
+## example
+
+```
+mysql> select
bitmap_to_string(bitmap_subset_in_range(bitmap_from_string('1,2,3,4,5'), 1, 4))
value;
Review comment:
这两个示例不太明显,没法体现出来是 值比较,还是下标比较。
##########
File path: be/test/exprs/bitmap_function_test.cpp
##########
@@ -446,6 +446,40 @@ TEST_F(BitmapFunctionsTest, bitmap_from_string) {
}
}
+TEST_F(BitmapFunctionsTest, bitmap_subset_in_range) {
+ // null
+ StringVal res = BitmapFunctions::bitmap_subset_in_range(ctx,
StringVal::null(), IntVal(1), IntVal(3));
+ ASSERT_TRUE(res.is_null);
+
+ // empty
+ BitmapValue bitmap0;
+ StringVal empty_str = convert_bitmap_to_string(ctx, bitmap0);
+ res = BitmapFunctions::bitmap_subset_in_range(ctx, empty_str, IntVal(1),
IntVal(3));
+ BigIntVal result = BitmapFunctions::bitmap_count(ctx, res);
+ ASSERT_EQ(BigIntVal(0), result);
+
+ // normal
+ BitmapValue
bitmap1({0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,208,23,24,25,26,27,28,29,30,31,32,33,100,200,500});
+
+ StringVal bitmap_src = convert_bitmap_to_string(ctx, bitmap1);
+ res = BitmapFunctions::bitmap_subset_in_range(ctx, bitmap_src, IntVal(30),
IntVal(200));
+ result = BitmapFunctions::bitmap_count(ctx, res);
+ ASSERT_EQ(BigIntVal(5), result);
+
+ res = BitmapFunctions::bitmap_subset_in_range(ctx, bitmap_src, IntVal(0),
IntVal(1));
+ result = BitmapFunctions::bitmap_count(ctx, res);
+ ASSERT_EQ(BigIntVal(1), result);
+
+ res = BitmapFunctions::bitmap_subset_in_range(ctx, bitmap_src, IntVal(11),
IntVal(15));
+ result = BitmapFunctions::bitmap_count(ctx, res);
+ ASSERT_EQ(BigIntVal(4), result);
+
+ // innormal
+ res = BitmapFunctions::bitmap_subset_in_range(ctx, bitmap_src, IntVal(30),
IntVal(20));
+ ASSERT_TRUE(res.is_null);
Review comment:
add unit tests for negative range, null range, MAX_INT64, MIN_INT64, etc.
##########
File path: be/src/exprs/bitmap_function.cpp
##########
@@ -597,6 +597,25 @@ BooleanVal
BitmapFunctions::bitmap_has_any(FunctionContext* ctx, const StringVal
return {bitmap.cardinality() != 0};
}
+StringVal BitmapFunctions::bitmap_subset_in_range(FunctionContext* ctx, const
StringVal& src,
+ const IntVal& range_start,
const IntVal& range_end) {
+ if (src.is_null) {
+ return StringVal::null();
+ }
+ if (range_start.val >= range_end.val) {
Review comment:
start and end can also be null, need to check it.
And what if start or end is negtive number.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]