This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-unstable
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 836021ac2edf507cdc182c2fd44e1a184551560a
Author: zhangstar333 <87313068+zhangstar...@users.noreply.github.com>
AuthorDate: Tue Nov 8 14:10:12 2022 +0800

    [Bug](Bitmap) fix sub_bitmap calculate wrong result to return null (#13978)
    
    fix sub_bitmap calculate wrong result to return null
---
 be/src/util/bitmap_value.h                         | 89 +++++++++++++++++-----
 .../docs/ecosystem/external-table/jdbc-of-doris.md |  2 +-
 .../docs/ecosystem/external-table/jdbc-of-doris.md |  2 +-
 .../bitmap_functions/test_bitmap_function.out      | 12 +++
 .../bitmap_functions/test_bitmap_function.groovy   |  7 +-
 5 files changed, 88 insertions(+), 24 deletions(-)

diff --git a/be/src/util/bitmap_value.h b/be/src/util/bitmap_value.h
index 2cbc0c00f9..e8f10a4f39 100644
--- a/be/src/util/bitmap_value.h
+++ b/be/src/util/bitmap_value.h
@@ -1682,19 +1682,35 @@ public:
      */
     int64_t sub_range(const int64_t& range_start, const int64_t& range_end,
                       BitmapValue* ret_bitmap) {
-        int64_t count = 0;
-        for (auto it = _bitmap.begin(); it != _bitmap.end(); ++it) {
-            if (*it < range_start) {
-                continue;
-            }
-            if (*it < range_end) {
-                ret_bitmap->add(*it);
-                ++count;
+        switch (_type) {
+        case EMPTY:
+            return 0;
+        case SINGLE: {
+            //only single value, so _sv must in [range_start,range_end)
+            if (range_start <= _sv && _sv < range_end) {
+                ret_bitmap->add(_sv);
+                return 1;
             } else {
-                break;
+                return 0;
             }
         }
-        return count;
+        case BITMAP: {
+            int64_t count = 0;
+            for (auto it = _bitmap.begin(); it != _bitmap.end(); ++it) {
+                if (*it < range_start) {
+                    continue;
+                }
+                if (*it < range_end) {
+                    ret_bitmap->add(*it);
+                    ++count;
+                } else {
+                    break;
+                }
+            }
+            return count;
+        }
+        }
+        return 0;
     }
 
     /**
@@ -1705,19 +1721,35 @@ public:
      */
     int64_t sub_limit(const int64_t& range_start, const int64_t& 
cardinality_limit,
                       BitmapValue* ret_bitmap) {
-        int64_t count = 0;
-        for (auto it = _bitmap.begin(); it != _bitmap.end(); ++it) {
-            if (*it < range_start) {
-                continue;
-            }
-            if (count < cardinality_limit) {
-                ret_bitmap->add(*it);
-                ++count;
+        switch (_type) {
+        case EMPTY:
+            return 0;
+        case SINGLE: {
+            //only single value, so range_start must less than _sv
+            if (range_start > _sv) {
+                return 0;
             } else {
-                break;
+                ret_bitmap->add(_sv);
+                return 1;
             }
         }
-        return count;
+        case BITMAP: {
+            int64_t count = 0;
+            for (auto it = _bitmap.begin(); it != _bitmap.end(); ++it) {
+                if (*it < range_start) {
+                    continue;
+                }
+                if (count < cardinality_limit) {
+                    ret_bitmap->add(*it);
+                    ++count;
+                } else {
+                    break;
+                }
+            }
+            return count;
+        }
+        }
+        return 0;
     }
 
     /**
@@ -1726,8 +1758,23 @@ public:
      * Analog of the substring string function, but for bitmap.
      */
     int64_t offset_limit(const int64_t& offset, const int64_t& limit, 
BitmapValue* ret_bitmap) {
-        if (std::abs(offset) >= _bitmap.cardinality()) {
+        switch (_type) {
+        case EMPTY:
             return 0;
+        case SINGLE: {
+            //only single value, so offset must start 0
+            if (offset == 0) {
+                ret_bitmap->add(_sv);
+                return 1;
+            } else {
+                return 0;
+            }
+        }
+        case BITMAP: {
+            if (std::abs(offset) >= _bitmap.cardinality()) {
+                return 0;
+            }
+        }
         }
         int64_t abs_offset = offset;
         if (offset < 0) {
diff --git a/docs/en/docs/ecosystem/external-table/jdbc-of-doris.md 
b/docs/en/docs/ecosystem/external-table/jdbc-of-doris.md
index 1eb5ce09a0..029e358957 100644
--- a/docs/en/docs/ecosystem/external-table/jdbc-of-doris.md
+++ b/docs/en/docs/ecosystem/external-table/jdbc-of-doris.md
@@ -75,7 +75,7 @@ Parameter Description:
 | **password**     | Password information corresponding to the user。|
 | **jdbc_url**     | The URL protocol of JDBC, including database type, IP 
address, port number and database name, has different formats for different 
database protocols. for example mysql: "jdbc:mysql://127.0.0.1:3306/test"。|
 | **driver_class** | The class name of the driver package for accessing the 
external database,for example mysql:com.mysql.jdbc.Driver. |
-| **driver_url**   | The package driver URL used to download and access 
external databases。http://IP:port/mysql-connector-java-5.1.47.jar .|
+| **driver_url**   | The package driver URL used to download and access 
external databases。http://IP:port/mysql-connector-java-5.1.47.jar . During the 
local test of one BE, the jar package can be placed in the local path, 
"driver_url"=“ file:///home/disk1/pathTo/mysql-connector-java-5.1.47.jar ", In 
case of multiple BE test,  Must ensure that they have the same path information|
 | **resource**     | The resource name that depends on when creating the 
external table in Doris corresponds to the name when creating the resource in 
the previous step.|
 | **table**        | The table name mapped to the external database when 
creating the external table in Doris.|
 | **table_type**   | When creating an appearance in Doris, the table comes 
from that database. for example mysql,postgresql,sqlserver,oracle.|
diff --git a/docs/zh-CN/docs/ecosystem/external-table/jdbc-of-doris.md 
b/docs/zh-CN/docs/ecosystem/external-table/jdbc-of-doris.md
index 461fa5838b..3d8f8daf66 100644
--- a/docs/zh-CN/docs/ecosystem/external-table/jdbc-of-doris.md
+++ b/docs/zh-CN/docs/ecosystem/external-table/jdbc-of-doris.md
@@ -72,7 +72,7 @@ PROPERTIES (
 | **password**     | 该用户对应的密码信息 |
 | **jdbc_url**     | JDBC的URL协议,包括数据库类型,IP地址,端口号和数据库名,不同数据库协议格式不一样。例如mysql: 
"jdbc:mysql://127.0.0.1:3306/test"。|
 | **driver_class** | 访问外表数据库的驱动包类名,例如mysql是:com.mysql.jdbc.Driver. |
-| **driver_url**   | 
用于下载访问外部数据库的jar包驱动URL。http://IP:port/mysql-connector-java-5.1.47.jar |
+| **driver_url**   | 
用于下载访问外部数据库的jar包驱动URL。http://IP:port/mysql-connector-java-5.1.47.jar。本地单机测试时,可将jar包放在本地路径下,"driver_url"="file:///home/disk1/pathTo/mysql-connector-java-5.1.47.jar",多机时需保证具有完全相同的路径信息。
 |
 | **resource**     | 在Doris中建立外表时依赖的资源名,对应上步创建资源时的名字。|
 | **table**        | 在Doris中建立外表时,与外部数据库相映射的表名。|
 | **table_type**   | 
在Doris中建立外表时,该表来自那个数据库。例如mysql,postgresql,sqlserver,oracle|
diff --git 
a/regression-test/data/query_p0/sql_functions/bitmap_functions/test_bitmap_function.out
 
b/regression-test/data/query_p0/sql_functions/bitmap_functions/test_bitmap_function.out
index 74ea0e50ff..ed771ea325 100644
--- 
a/regression-test/data/query_p0/sql_functions/bitmap_functions/test_bitmap_function.out
+++ 
b/regression-test/data/query_p0/sql_functions/bitmap_functions/test_bitmap_function.out
@@ -259,3 +259,15 @@ false
 -- !sql --
 [3, 4, 100, 200]
 
+-- !sql --
+1,2,3
+
+-- !sql --
+1
+
+-- !sql --
+100
+
+-- !sql --
+20221103
+
diff --git 
a/regression-test/suites/query_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy
 
b/regression-test/suites/query_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy
index b429b30668..8669f961a4 100644
--- 
a/regression-test/suites/query_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy
@@ -183,7 +183,12 @@ suite("test_bitmap_function") {
     qt_sql """ select orthogonal_bitmap_intersect_count(members, tag_group, 
1150000, 1150001, 390006) from ${arthogonalBitmapTable} where  tag_group in ( 
1150000, 1150001, 390006); """
     qt_sql """ select orthogonal_bitmap_union_count(members) from 
${arthogonalBitmapTable} where  tag_group in ( 1150000, 1150001, 390006);  """
 
-    qt_sql """ select bitmap_to_array(user_id) from ${intersectCountTable}; """
+    qt_sql """ select bitmap_to_array(user_id) from ${intersectCountTable} 
order by dt desc; """
     qt_sql """ select bitmap_to_array(bitmap_empty()); """
     qt_sql """ select bitmap_to_array(bitmap_from_string('100,200,3,4')); """
+
+    qt_sql """ select 
bitmap_to_string(sub_bitmap(bitmap_from_string('1,2,3,4,5'), 0, 3)) value; """
+    qt_sql """ select bitmap_to_string(sub_bitmap(bitmap_from_string('1'), 0, 
3)) value;  """
+    qt_sql """ select 
bitmap_to_string(bitmap_subset_limit(bitmap_from_string('100'), 0, 3)) value;  
"""
+    qt_sql """ select 
bitmap_to_string(bitmap_subset_in_range(bitmap_from_string('20221103'), 0, 
20221104)) date_list_bitmap;  """
 }


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

Reply via email to