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

lihaopeng pushed a commit to branch vectorized
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/vectorized by this push:
     new 3b09779  [Bug] Fix function nulllable not match and largetint cast 
failed (#7659)
3b09779 is described below

commit 3b09779377f0bcb71a01b4116c889947f13f33a0
Author: HappenLee <happen...@hotmail.com>
AuthorDate: Thu Jan 6 21:52:51 2022 -0600

    [Bug] Fix function nulllable not match and largetint cast failed (#7659)
    
    Co-authored-by: lihaopeng <lihaop...@baidu.com>
---
 be/src/vec/common/cow.h                         |  8 ++++----
 be/src/vec/core/block.cpp                       |  6 ++++--
 be/src/vec/data_types/data_type_number_base.cpp |  2 +-
 be/src/vec/functions/date_time_transforms.h     |  8 +++++---
 be/src/vec/io/io_helper.h                       | 18 ++++--------------
 gensrc/script/doris_builtins_functions.py       | 10 +++++-----
 6 files changed, 23 insertions(+), 29 deletions(-)

diff --git a/be/src/vec/common/cow.h b/be/src/vec/common/cow.h
index 08edb89..58ae14d 100644
--- a/be/src/vec/common/cow.h
+++ b/be/src/vec/common/cow.h
@@ -105,10 +105,6 @@ protected:
         return *this;
     }
 
-    unsigned int use_count() const {
-        return ref_counter.load();
-    }
-
     void add_ref() {
         ++ref_counter;
     }
@@ -265,6 +261,10 @@ protected:
 public:
     using MutablePtr = mutable_ptr<Derived>;
 
+    unsigned int use_count() const {
+        return ref_counter.load();
+    }
+
 protected:
     template <typename T>
     class immutable_ptr : public intrusive_ptr<const T> {
diff --git a/be/src/vec/core/block.cpp b/be/src/vec/core/block.cpp
index b52257d..a5e445d 100644
--- a/be/src/vec/core/block.cpp
+++ b/be/src/vec/core/block.cpp
@@ -646,7 +646,8 @@ void Block::clear_column_data(int column_size) noexcept {
         }
     }
     for (auto& d : data) {
-        (*std::move(d.column)).mutate()->clear();
+        DCHECK(d.column->use_count() == 1);
+        (*std::move(d.column)).assume_mutable()->clear();
     }
 }
 
@@ -691,7 +692,8 @@ Status Block::filter_block(Block* block, int 
filter_column_id, int column_to_kee
     if (auto* nullable_column = 
check_and_get_column<ColumnNullable>(*filter_column)) {
         ColumnPtr nested_column = nullable_column->get_nested_column_ptr();
 
-        MutableColumnPtr mutable_holder = (*std::move(nested_column)).mutate();
+        MutableColumnPtr mutable_holder = nested_column->use_count() == 1 ?
+                nested_column->assume_mutable() : 
nested_column->clone_resized(nested_column->size());
 
         ColumnUInt8* concrete_column = 
typeid_cast<ColumnUInt8*>(mutable_holder.get());
         if (!concrete_column) {
diff --git a/be/src/vec/data_types/data_type_number_base.cpp 
b/be/src/vec/data_types/data_type_number_base.cpp
index ee94a37..01a4248 100644
--- a/be/src/vec/data_types/data_type_number_base.cpp
+++ b/be/src/vec/data_types/data_type_number_base.cpp
@@ -35,7 +35,7 @@ namespace doris::vectorized {
 template <typename T>
 void DataTypeNumberBase<T>::to_string(const IColumn& column, size_t row_num,
                                       BufferWritable& ostr) const {
-    if constexpr (std::is_same<T, __int128_t>::value || std::is_same<T, 
UInt128>::value) {
+    if constexpr (std::is_same<T, UInt128>::value) {
         std::string hex = int128_to_string(
                 assert_cast<const 
ColumnVector<T>&>(*column.convert_to_full_column_if_const().get())
                         .get_data()[row_num]);
diff --git a/be/src/vec/functions/date_time_transforms.h 
b/be/src/vec/functions/date_time_transforms.h
index a34b53d..eaab918 100644
--- a/be/src/vec/functions/date_time_transforms.h
+++ b/be/src/vec/functions/date_time_transforms.h
@@ -56,6 +56,7 @@ TIME_FUNCTION_IMPL(WeekOfYearImpl, weekofyear, 
week(mysql_week_mode(3)));
 TIME_FUNCTION_IMPL(DayOfYearImpl, dayofyear, day_of_year());
 TIME_FUNCTION_IMPL(DayOfMonthImpl, dayofmonth, day());
 TIME_FUNCTION_IMPL(DayOfWeekImpl, dayofweek, day_of_week());
+// TODO: the method should be always not nullable
 TIME_FUNCTION_IMPL(ToDaysImpl, to_days, daynr());
 TIME_FUNCTION_IMPL(ToYearWeekImpl, yearweek, year_week(mysql_week_mode(0)));
 struct ToDateImpl {
@@ -92,7 +93,7 @@ struct DayNameImpl {
             res_data[offset - 1] = 0;
         } else {
             auto len = strlen(day_name);
-            memcpy_small_allow_read_write_overflow15(&res_data[offset], 
day_name, len);
+            memcpy(&res_data[offset], day_name, len);
             offset += len + 1;
             res_data[offset - 1] = 0;
         }
@@ -113,8 +114,8 @@ struct MonthNameImpl {
             res_data[offset - 1] = 0;
         } else {
             auto len = strlen(month_name);
-            memcpy_small_allow_read_write_overflow15(&res_data[offset], 
month_name, len);
-            offset += len + 1;
+            memcpy(&res_data[offset], month_name, len);
+            offset += (len + 1);
             res_data[offset - 1] = 0;
         }
         return offset;
@@ -148,6 +149,7 @@ struct DateFormatImpl {
     }
 };
 
+// TODO: This function should be depend on argments not always nullable
 struct FromUnixTimeImpl {
     using FromType = Int32;
 
diff --git a/be/src/vec/io/io_helper.h b/be/src/vec/io/io_helper.h
index fb9371f..ab3caa7 100644
--- a/be/src/vec/io/io_helper.h
+++ b/be/src/vec/io/io_helper.h
@@ -54,19 +54,9 @@ inline Int128 decimal_scale_multiplier<Int128>(UInt32 scale) 
{
 }
 
 inline std::string int128_to_string(__int128_t value) {
-    char buffer[128];
-    char* d = std::end(buffer);
-    do {
-        --d;
-        *d = "0123456789"[value % 10];
-        value /= 10;
-    } while (value != 0);
-    if (value < 0) {
-        --d;
-        *d = '-';
-    }
-    int len = std::end(buffer) - d;
-    return std::string(d, len);
+    fmt::memory_buffer buffer;
+    fmt::format_to(buffer, "{}", value);
+    return std::string(buffer.data(), buffer.size());
 }
 
 inline std::string int128_to_string(UInt128 value) {
@@ -84,7 +74,7 @@ void write_text(Decimal<T> value, UInt32 scale, std::ostream& 
ostr) {
     if (scale) {
         whole_part = value / decimal_scale_multiplier<T>(scale);
     }
-    if constexpr (std::is_same<T, __int128_t>::value || std::is_same<T, 
UInt128>::value) {
+    if constexpr (std::is_same<T, __int128_t>::value) {
         ostr << int128_to_string(whole_part);
     } else {
         ostr << whole_part;
diff --git a/gensrc/script/doris_builtins_functions.py 
b/gensrc/script/doris_builtins_functions.py
index 6d64fcd..c777876 100755
--- a/gensrc/script/doris_builtins_functions.py
+++ b/gensrc/script/doris_builtins_functions.py
@@ -139,14 +139,14 @@ visible_functions = [
         '', '', 'vec', 'ALWAYS_NULLABLE'],
     [['from_unixtime'], 'VARCHAR', ['INT'],
         
'_ZN5doris18TimestampFunctions9from_unixEPN9doris_udf15FunctionContextERKNS1_6IntValE',
-        '', '', 'vec', ''],
+        '', '', 'vec', 'ALWAYS_NULLABLE'],
     [['from_unixtime'], 'VARCHAR', ['INT', 'VARCHAR'],
         '_ZN5doris18TimestampFunctions9from_unixEPN9doris_udf'
         '15FunctionContextERKNS1_6IntValERKNS1_9StringValE',
         '_ZN5doris18TimestampFunctions14format_prepareEPN9doris_udf'
         '15FunctionContextENS2_18FunctionStateScopeE',
         '_ZN5doris18TimestampFunctions12format_closeEPN9doris_udf'
-        '15FunctionContextENS2_18FunctionStateScopeE', 'vec', ''],
+        '15FunctionContextENS2_18FunctionStateScopeE', 'vec', 
'ALWAYS_NULLABLE'],
     [['from_unixtime'], 'VARCHAR', ['INT', 'STRING'],
         '_ZN5doris18TimestampFunctions9from_unixEPN9doris_udf'
         '15FunctionContextERKNS1_6IntValERKNS1_9StringValE',
@@ -175,7 +175,7 @@ visible_functions = [
         '', '', 'vec', 'ALWAYS_NULLABLE'],
     [['to_days'], 'INT', ['DATE'],
         
'_ZN5doris18TimestampFunctions7to_daysEPN9doris_udf15FunctionContextERKNS1_11DateTimeValE',
-        '', '', 'vec', ''],
+        '', '', 'vec', 'ALWAYS_NULLABLE'],
 
      [['year'], 'INT', ['DATETIME'],
         
'_ZN5doris18TimestampFunctions4yearEPN9doris_udf15FunctionContextERKNS1_11DateTimeValE',
@@ -525,9 +525,9 @@ visible_functions = [
 
     # Math builtin functions
     [['pi'], 'DOUBLE', [],
-        '_ZN5doris13MathFunctions2piEPN9doris_udf15FunctionContextE', '', '', 
'vec', 'ALWAYS_NULLABLE'],
+        '_ZN5doris13MathFunctions2piEPN9doris_udf15FunctionContextE', '', '', 
'vec', 'ALWAYS_NOT_NULLABLE'],
     [['e'], 'DOUBLE', [],
-        '_ZN5doris13MathFunctions1eEPN9doris_udf15FunctionContextE', '', '', 
'vec', 'ALWAYS_NULLABLE'],
+        '_ZN5doris13MathFunctions1eEPN9doris_udf15FunctionContextE', '', '', 
'vec', 'ALWAYS_NOT_NULLABLE'],
 
     [['abs'], 'DOUBLE', ['DOUBLE'],
         
'_ZN5doris13MathFunctions3absEPN9doris_udf15FunctionContextERKNS1_9DoubleValE', 
'', '', 'vec', ''],

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

Reply via email to