You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/01/13 06:13:53 UTC

[doris] 02/05: [Bug](bitmap) Fix bitmap_from_string for null constant (#15698)

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

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

commit 34b817625a59ea29191f5e08d52e3caa34d01490
Author: Gabriel <ga...@gmail.com>
AuthorDate: Mon Jan 9 10:21:08 2023 +0800

    [Bug](bitmap) Fix bitmap_from_string for null constant (#15698)
---
 be/src/vec/columns/column_const.cpp                |  3 ++-
 be/src/vec/functions/function_bitmap.cpp           | 16 +++++++++++-----
 .../data/datatype_p0/bitmap/test_bitmap_const.out  |  4 ++++
 .../datatype_p0/bitmap/test_bitmap_const.groovy    | 22 ++++++++++++++++++++++
 4 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/be/src/vec/columns/column_const.cpp b/be/src/vec/columns/column_const.cpp
index 4720b4cd02..d2cb9ef7e7 100644
--- a/be/src/vec/columns/column_const.cpp
+++ b/be/src/vec/columns/column_const.cpp
@@ -36,7 +36,8 @@ ColumnConst::ColumnConst(const ColumnPtr& data_, size_t s_) : data(data_), s(s_)
 
     if (data->size() != 1) {
         LOG(FATAL) << fmt::format(
-                "Incorrect size of nested column in constructor of ColumnConst: {}, must be 1.");
+                "Incorrect size of nested column in constructor of ColumnConst: {}, must be 1.",
+                data->size());
     }
 }
 
diff --git a/be/src/vec/functions/function_bitmap.cpp b/be/src/vec/functions/function_bitmap.cpp
index 247dcab19b..4350d3b256 100644
--- a/be/src/vec/functions/function_bitmap.cpp
+++ b/be/src/vec/functions/function_bitmap.cpp
@@ -183,11 +183,17 @@ struct BitmapFromString {
     static constexpr auto name = "bitmap_from_string";
 
     static Status vector(const ColumnString::Chars& data, const ColumnString::Offsets& offsets,
-                         std::vector<BitmapValue>& res, NullMap& null_map) {
-        auto size = offsets.size();
-        res.reserve(size);
+                         std::vector<BitmapValue>& res, NullMap& null_map,
+                         size_t input_rows_count) {
+        res.reserve(input_rows_count);
         std::vector<uint64_t> bits;
-        for (size_t i = 0; i < size; ++i) {
+        if (offsets.size() == 0 && input_rows_count == 1) {
+            // For NULL constant
+            res.emplace_back();
+            null_map[0] = 1;
+            return Status::OK();
+        }
+        for (size_t i = 0; i < input_rows_count; ++i) {
             const char* raw_str = reinterpret_cast<const char*>(&data[offsets[i - 1]]);
             int64_t str_size = offsets[i] - offsets[i - 1];
 
@@ -272,7 +278,7 @@ public:
             const auto& str_column = static_cast<const ColumnString&>(*argument_column);
             const ColumnString::Chars& data = str_column.get_chars();
             const ColumnString::Offsets& offsets = str_column.get_offsets();
-            Impl::vector(data, offsets, res, null_map);
+            Impl::vector(data, offsets, res, null_map, input_rows_count);
         } else if constexpr (std::is_same_v<typename Impl::ArgumentType, DataTypeArray>) {
             auto argument_type = remove_nullable(
                     assert_cast<const DataTypeArray&>(*block.get_by_position(arguments[0]).type)
diff --git a/regression-test/data/datatype_p0/bitmap/test_bitmap_const.out b/regression-test/data/datatype_p0/bitmap/test_bitmap_const.out
new file mode 100644
index 0000000000..2871306509
--- /dev/null
+++ b/regression-test/data/datatype_p0/bitmap/test_bitmap_const.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !select --
+\N
+
diff --git a/regression-test/suites/datatype_p0/bitmap/test_bitmap_const.groovy b/regression-test/suites/datatype_p0/bitmap/test_bitmap_const.groovy
new file mode 100644
index 0000000000..e824ed631b
--- /dev/null
+++ b/regression-test/suites/datatype_p0/bitmap/test_bitmap_const.groovy
@@ -0,0 +1,22 @@
+// 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.
+
+suite("test_bitmap_const") {
+    qt_select "select bitmap_from_string(     cast(null as TEXT));"
+}
+
+


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