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

gabriellee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new a8999f506ea [refine](time) use TimeValue to refine repetitive logic 
and remove unused code. (#42978)
a8999f506ea is described below

commit a8999f506eae2a4245558f3e1fb57b64a8f14d94
Author: Mryange <[email protected]>
AuthorDate: Mon Nov 11 14:49:14 2024 +0800

    [refine](time) use TimeValue to refine repetitive logic and remove unused 
code. (#42978)
---
 .../vec/data_types/serde/data_type_time_serde.cpp  | 27 ----------------------
 be/src/vec/data_types/serde/data_type_time_serde.h | 18 ---------------
 be/src/vec/functions/function_cast.h               | 11 ++++-----
 .../function_date_or_datetime_computation.h        | 14 +++++------
 be/src/vec/runtime/time_value.h                    | 11 +++++++++
 5 files changed, 23 insertions(+), 58 deletions(-)

diff --git a/be/src/vec/data_types/serde/data_type_time_serde.cpp 
b/be/src/vec/data_types/serde/data_type_time_serde.cpp
index 19b0b1cf6e5..01e9b5ecd5d 100644
--- a/be/src/vec/data_types/serde/data_type_time_serde.cpp
+++ b/be/src/vec/data_types/serde/data_type_time_serde.cpp
@@ -19,33 +19,6 @@
 namespace doris {
 namespace vectorized {
 
-template <bool is_binary_format>
-Status DataTypeTimeSerDe::_write_column_to_mysql(const IColumn& column,
-                                                 
MysqlRowBuffer<is_binary_format>& result,
-                                                 int row_idx, bool col_const,
-                                                 const FormatOptions& options) 
const {
-    auto& data = assert_cast<const ColumnFloat64&>(column).get_data();
-    const auto col_index = index_check_const(row_idx, col_const);
-    if (UNLIKELY(0 != result.push_time(data[col_index]))) {
-        return Status::InternalError("pack mysql buffer failed.");
-    }
-    return Status::OK();
-}
-
-Status DataTypeTimeSerDe::write_column_to_mysql(const IColumn& column,
-                                                MysqlRowBuffer<true>& 
row_buffer, int row_idx,
-                                                bool col_const,
-                                                const FormatOptions& options) 
const {
-    return _write_column_to_mysql(column, row_buffer, row_idx, col_const, 
options);
-}
-
-Status DataTypeTimeSerDe::write_column_to_mysql(const IColumn& column,
-                                                MysqlRowBuffer<false>& 
row_buffer, int row_idx,
-                                                bool col_const,
-                                                const FormatOptions& options) 
const {
-    return _write_column_to_mysql(column, row_buffer, row_idx, col_const, 
options);
-}
-
 Status DataTypeTimeV2SerDe::write_column_to_mysql(const IColumn& column,
                                                   MysqlRowBuffer<true>& 
row_buffer, int row_idx,
                                                   bool col_const,
diff --git a/be/src/vec/data_types/serde/data_type_time_serde.h 
b/be/src/vec/data_types/serde/data_type_time_serde.h
index d9a373b2f5a..24e3da8ec21 100644
--- a/be/src/vec/data_types/serde/data_type_time_serde.h
+++ b/be/src/vec/data_types/serde/data_type_time_serde.h
@@ -28,24 +28,6 @@ namespace doris {
 class JsonbOutStream;
 
 namespace vectorized {
-class Arena;
-
-class DataTypeTimeSerDe : public DataTypeNumberSerDe<Float64> {
-public:
-    DataTypeTimeSerDe(int nesting_level = 1) : 
DataTypeNumberSerDe<Float64>(nesting_level) {};
-
-    Status write_column_to_mysql(const IColumn& column, MysqlRowBuffer<true>& 
row_buffer,
-                                 int row_idx, bool col_const,
-                                 const FormatOptions& options) const override;
-    Status write_column_to_mysql(const IColumn& column, MysqlRowBuffer<false>& 
row_buffer,
-                                 int row_idx, bool col_const,
-                                 const FormatOptions& options) const override;
-
-private:
-    template <bool is_binary_format>
-    Status _write_column_to_mysql(const IColumn& column, 
MysqlRowBuffer<is_binary_format>& result,
-                                  int row_idx, bool col_const, const 
FormatOptions& options) const;
-};
 class DataTypeTimeV2SerDe : public DataTypeNumberSerDe<Float64> {
 public:
     DataTypeTimeV2SerDe(int scale = 0, int nesting_level = 1)
diff --git a/be/src/vec/functions/function_cast.h 
b/be/src/vec/functions/function_cast.h
index 0e567a2b743..c2195fd7e69 100644
--- a/be/src/vec/functions/function_cast.h
+++ b/be/src/vec/functions/function_cast.h
@@ -94,6 +94,7 @@
 #include "vec/functions/function_convert_tz.h"
 #include "vec/functions/function_helpers.h"
 #include "vec/io/reader_buffer.h"
+#include "vec/runtime/time_value.h"
 #include "vec/runtime/vdatetime_value.h"
 #include "vec/utils/util.hpp"
 
@@ -145,7 +146,7 @@ struct TimeCast {
         } else {
             if (VecDateTimeValue dv {}; dv.from_date_str(s, len, 
local_time_zone)) {
                 // can be parse as a datetime
-                x = dv.hour() * 3600 + dv.minute() * 60 + dv.second();
+                x = TimeValue::make_time(dv.hour(), dv.minute(), dv.second());
                 return true;
             }
             return false;
@@ -210,7 +211,7 @@ struct TimeCast {
         if (minute >= 60 || second >= 60) {
             return false;
         }
-        x = hour * 3600 + minute * 60 + second;
+        x = TimeValue::make_time(hour, minute, second);
         return true;
     }
     // Cast from number
@@ -227,7 +228,7 @@ struct TimeCast {
         if (minute >= 60 || second >= 60) {
             return false;
         }
-        x = hour * 3600 + minute * 60 + second;
+        x = TimeValue::make_time(hour, minute, second);
         return true;
     }
     template <typename S>
@@ -243,7 +244,7 @@ struct TimeCast {
         if (minute >= 60 || second >= 60) {
             return false;
         }
-        x = hour * 3600 + minute * 60 + second;
+        x = TimeValue::make_time(hour, minute, second);
         return true;
     }
 };
@@ -428,7 +429,6 @@ struct ConvertImpl {
                     for (size_t i = 0; i < size; ++i) {
                         (*vec_null_map_to)[i] = !TimeCast::try_parse_time(
                                 vec_from[i], vec_to[i], 
context->state()->timezone_obj());
-                        vec_to[i] *= (1000 * 1000);
                     }
                     block.get_by_position(result).column =
                             ColumnNullable::create(std::move(col_to), 
std::move(col_null_map_to));
@@ -1061,7 +1061,6 @@ bool try_parse_impl(typename DataType::FieldType& x, 
ReadBuffer& rb, FunctionCon
         auto s = rb.position();
         rb.position() = rb.end(); // make is_all_read = true
         auto ret = TimeCast::try_parse_time(s, len, x, 
context->state()->timezone_obj());
-        x *= (1000 * 1000);
         return ret;
     }
     if constexpr (std::is_floating_point_v<typename DataType::FieldType>) {
diff --git a/be/src/vec/functions/function_date_or_datetime_computation.h 
b/be/src/vec/functions/function_date_or_datetime_computation.h
index 2dd71ec31be..90221e66c21 100644
--- a/be/src/vec/functions/function_date_or_datetime_computation.h
+++ b/be/src/vec/functions/function_date_or_datetime_computation.h
@@ -61,6 +61,7 @@
 #include "vec/data_types/data_type_time_v2.h"
 #include "vec/functions/function.h"
 #include "vec/functions/function_helpers.h"
+#include "vec/runtime/time_value.h"
 #include "vec/runtime/vdatetime_value.h"
 #include "vec/utils/util.hpp"
 
@@ -307,7 +308,7 @@ struct TimeDiffImpl {
                 return (double)diff_m;
             }
         } else {
-            return (double)((1000 * 1000) * ts0.second_diff(ts1));
+            return TimeValue::from_second(ts0.second_diff(ts1));
         }
     }
     static DataTypes get_variadic_argument_types() {
@@ -993,9 +994,8 @@ struct CurrentTimeImpl {
         VecDateTimeValue dtv;
         dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
                           context->state()->timezone_obj());
-        double time = dtv.hour() * 3600l + dtv.minute() * 60l + dtv.second();
-        time *= (1000 * 1000);
-        col_to->insert_data(const_cast<const 
char*>(reinterpret_cast<char*>(&time)), 0);
+        auto time = TimeValue::make_time(dtv.hour(), dtv.minute(), 
dtv.second());
+        col_to->insert_value(time);
         block.get_by_position(result).column =
                 ColumnConst::create(std::move(col_to), input_rows_count);
         return Status::OK();
@@ -1014,8 +1014,8 @@ struct TimeToSecImpl {
 
         auto& res_data = res_col->get_data();
         for (int i = 0; i < input_rows_count; ++i) {
-            res_data[i] =
-                    
cast_set<int>(static_cast<int64_t>(column_data.get_element(i)) / (1000 * 1000));
+            res_data[i] = 
cast_set<int>(static_cast<int64_t>(column_data.get_element(i)) /
+                                        (TimeValue::ONE_SECOND_MICROSECONDS));
         }
         block.replace_by_position(result, std::move(res_col));
 
@@ -1034,7 +1034,7 @@ struct SecToTimeImpl {
         auto res_col = ColumnFloat64::create(input_rows_count);
         auto& res_data = res_col->get_data();
         for (int i = 0; i < input_rows_count; ++i) {
-            res_data[i] = (1000 * 1000) * 
static_cast<double>(column_data.get_element(i));
+            res_data[i] = TimeValue::from_second(column_data.get_element(i));
         }
 
         block.replace_by_position(result, std::move(res_col));
diff --git a/be/src/vec/runtime/time_value.h b/be/src/vec/runtime/time_value.h
index 3f9f378503e..eaefa3b7658 100644
--- a/be/src/vec/runtime/time_value.h
+++ b/be/src/vec/runtime/time_value.h
@@ -56,6 +56,13 @@ public:
         return static_cast<int64_t>(time);
     }
 
+    static TimeType make_time(int64_t hour, int64_t minute, int64_t second,
+                              int64_t microsecond = 0) {
+        int64_t value = hour * ONE_HOUR_MICROSECONDS + minute * 
ONE_MINUTE_MICROSECONDS +
+                        second * ONE_SECOND_MICROSECONDS + microsecond;
+        return static_cast<TimeType>(value);
+    }
+
     static std::string to_string(TimeType time, int scale) {
         return timev2_to_buffer_from_double(time, scale);
     }
@@ -70,6 +77,10 @@ public:
     static int32_t second(TimeType time) {
         return (check_over_max_time(time) / ONE_SECOND_MICROSECONDS) % 
ONE_MINUTE_SECONDS;
     }
+
+    static TimeType from_second(int64_t sec) {
+        return static_cast<TimeType>(sec * ONE_SECOND_MICROSECONDS);
+    }
 };
 
 } // namespace doris


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to