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

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


The following commit(s) were added to refs/heads/branch-1.2-lts by this push:
     new 30145d2ccc [cherry-pick](#16194) pick remove mempool pr from master in 
default value iterator (#17120)
30145d2ccc is described below

commit 30145d2ccc5f036e6f27437f6729e8bb461f1738
Author: yiguolei <676222...@qq.com>
AuthorDate: Fri Feb 24 19:06:51 2023 +0800

    [cherry-pick](#16194) pick remove mempool pr from master in default value 
iterator (#17120)
    
    * [cherry-pick](#16194) pick remove mempool pr from master in default 
column iterator
    Remove mempool usage from default value column iterator. The mempool does 
not have memtracker but spark load will use it, then it will core.
    
    pick from ##16194
    ---------
    
    Co-authored-by: yiguolei <yiguo...@gmail.com>
---
 be/src/olap/rowset/segment_v2/column_reader.cpp    | 33 +++++-------
 be/src/olap/rowset/segment_v2/column_reader.h      |  8 +--
 .../correctness_p0/test_char_default_value.out     | 11 ++++
 .../correctness_p0/test_char_default_value.groovy  | 63 ++++++++++++++++++++++
 4 files changed, 89 insertions(+), 26 deletions(-)

diff --git a/be/src/olap/rowset/segment_v2/column_reader.cpp 
b/be/src/olap/rowset/segment_v2/column_reader.cpp
index 430251aac2..c8da3c8a7c 100644
--- a/be/src/olap/rowset/segment_v2/column_reader.cpp
+++ b/be/src/olap/rowset/segment_v2/column_reader.cpp
@@ -981,29 +981,22 @@ Status DefaultValueColumnIterator::init(const 
ColumnIteratorOptions& opts) {
             _is_default_value_null = true;
         } else {
             _type_size = _type_info->size();
-            _mem_value = reinterpret_cast<void*>(_pool->allocate(_type_size));
+            _mem_value.resize(_type_size);
             Status s = Status::OK();
-            if (_type_info->type() == OLAP_FIELD_TYPE_CHAR) {
-                int32_t length = _schema_length;
-                char* string_buffer = 
reinterpret_cast<char*>(_pool->allocate(length));
-                memset(string_buffer, 0, length);
-                memory_copy(string_buffer, _default_value.c_str(), 
_default_value.length());
-                ((Slice*)_mem_value)->size = length;
-                ((Slice*)_mem_value)->data = string_buffer;
-            } else if (_type_info->type() == OLAP_FIELD_TYPE_VARCHAR ||
-                       _type_info->type() == OLAP_FIELD_TYPE_HLL ||
-                       _type_info->type() == OLAP_FIELD_TYPE_OBJECT ||
-                       _type_info->type() == OLAP_FIELD_TYPE_STRING) {
-                int32_t length = _default_value.length();
-                char* string_buffer = 
reinterpret_cast<char*>(_pool->allocate(length));
-                memory_copy(string_buffer, _default_value.c_str(), length);
-                ((Slice*)_mem_value)->size = length;
-                ((Slice*)_mem_value)->data = string_buffer;
+            // If char length is 10, but default value is 'a' , it's length is 
1
+            // not fill 0 to the ending, because segment iterator will shrink 
the tail 0 char
+            if (_type_info->type() == OLAP_FIELD_TYPE_VARCHAR ||
+                _type_info->type() == OLAP_FIELD_TYPE_HLL ||
+                _type_info->type() == OLAP_FIELD_TYPE_OBJECT ||
+                _type_info->type() == OLAP_FIELD_TYPE_STRING ||
+                _type_info->type() == OLAP_FIELD_TYPE_CHAR) {
+                ((Slice*)_mem_value.data())->size = _default_value.length();
+                ((Slice*)_mem_value.data())->data = _default_value.data();
             } else if (_type_info->type() == OLAP_FIELD_TYPE_ARRAY) {
                 // TODO llj for Array default value
                 return Status::NotSupported("Array default type is 
unsupported");
             } else {
-                s = _type_info->from_string(_mem_value, _default_value, 
_precision, _scale);
+                s = _type_info->from_string(_mem_value.data(), _default_value, 
_precision, _scale);
             }
             if (!s.ok()) {
                 return s;
@@ -1030,7 +1023,7 @@ Status DefaultValueColumnIterator::next_batch(size_t* n, 
ColumnBlockView* dst, b
     } else {
         *has_null = false;
         for (int i = 0; i < *n; ++i) {
-            memcpy(dst->data(), _mem_value, _type_size);
+            memcpy(dst->data(), _mem_value.data(), _type_size);
             dst->advance(1);
         }
     }
@@ -1117,7 +1110,7 @@ void 
DefaultValueColumnIterator::_insert_many_default(vectorized::MutableColumnP
     if (_is_default_value_null) {
         dst->insert_many_defaults(n);
     } else {
-        insert_default_data(_type_info.get(), _type_size, _mem_value, dst, n);
+        insert_default_data(_type_info.get(), _type_size, _mem_value.data(), 
dst, n);
     }
 }
 
diff --git a/be/src/olap/rowset/segment_v2/column_reader.h 
b/be/src/olap/rowset/segment_v2/column_reader.h
index 5a86bdec10..81be872f3d 100644
--- a/be/src/olap/rowset/segment_v2/column_reader.h
+++ b/be/src/olap/rowset/segment_v2/column_reader.h
@@ -432,12 +432,10 @@ public:
               _default_value(default_value),
               _is_nullable(is_nullable),
               _type_info(std::move(type_info)),
-              _schema_length(schema_length),
               _is_default_value_null(false),
               _type_size(0),
               _precision(precision),
-              _scale(scale),
-              _pool(new MemPool()) {}
+              _scale(scale) {}
 
     Status init(const ColumnIteratorOptions& opts) override;
 
@@ -479,13 +477,11 @@ private:
     std::string _default_value;
     bool _is_nullable;
     TypeInfoPtr _type_info;
-    size_t _schema_length;
     bool _is_default_value_null;
     size_t _type_size;
     int _precision;
     int _scale;
-    void* _mem_value = nullptr;
-    std::unique_ptr<MemPool> _pool;
+    std::vector<char> _mem_value;
 
     // current rowid
     ordinal_t _current_rowid = 0;
diff --git a/regression-test/data/correctness_p0/test_char_default_value.out 
b/regression-test/data/correctness_p0/test_char_default_value.out
new file mode 100644
index 0000000000..870f1341de
--- /dev/null
+++ b/regression-test/data/correctness_p0/test_char_default_value.out
@@ -0,0 +1,11 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select --
+8      aaaaaaaa1       a       9       1
+7      aaaaaaaa1       ass     9       3
+6      aaaaaaaa        ass     8       3
+5      ss      ass     2       3
+4      aaaaaa  ass     6       3
+3      ss      ass     2       3
+2      ss      ass     2       3
+1      ss      ass     2       3
+
diff --git 
a/regression-test/suites/correctness_p0/test_char_default_value.groovy 
b/regression-test/suites/correctness_p0/test_char_default_value.groovy
new file mode 100644
index 0000000000..045e5175c6
--- /dev/null
+++ b/regression-test/suites/correctness_p0/test_char_default_value.groovy
@@ -0,0 +1,63 @@
+// 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_char_default_value") {
+    sql """
+        drop table if exists test_char_default_value;
+    """
+    
+    sql """
+        CREATE TABLE `test_char_default_value` (
+            `a` int(11) NULL,
+            `b` char(10) NULL DEFAULT "ss",
+            `c` varchar(10) NULL DEFAULT "ass"
+        ) ENGINE=OLAP
+        DUPLICATE KEY(`a`, `b`)
+        COMMENT 'OLAP'
+        DISTRIBUTED BY HASH(`a`) BUCKETS 1
+        PROPERTIES (
+        "replication_num" = "1",
+        "storage_format" = "V2",
+        "light_schema_change" = "true",
+        "disable_auto_compaction" = "false"
+        );
+    """
+
+    sql """
+        insert into test_char_default_value(a) values(1);
+    """
+
+    sql """ """
+    sql """ insert into test_char_default_value(a) values(2); """
+    sql """ insert into test_char_default_value(a) values(3); """
+    sql """ insert into test_char_default_value(a,b) values(4,'aaaaaa'); """
+    sql """ insert into test_char_default_value(a) values(5); """
+    sql """ insert into test_char_default_value(a,b) values(6,'aaaaaaaa'); """
+    sql """ insert into test_char_default_value(a,b) values(7,'aaaaaaaa1'); """
+    sql """ insert into test_char_default_value(a,b,c) 
values(8,'aaaaaaaa1','a'); """
+
+    qt_select """
+        select
+        a,b,c,length(b),length(c)
+        from
+        test_char_default_value order by a desc;
+    """
+
+    sql """
+        drop table if exists test_char_default_value;
+    """
+}


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

Reply via email to