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 19b0b1cf6e5894..01e9b5ecd5dfa4 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 -Status DataTypeTimeSerDe::_write_column_to_mysql(const IColumn& column, - MysqlRowBuffer& result, - int row_idx, bool col_const, - const FormatOptions& options) const { - auto& data = assert_cast(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& 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& 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& 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 d9a373b2f5a53d..24e3da8ec21609 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 { -public: - DataTypeTimeSerDe(int nesting_level = 1) : DataTypeNumberSerDe(nesting_level) {}; - - Status write_column_to_mysql(const IColumn& column, MysqlRowBuffer& row_buffer, - int row_idx, bool col_const, - const FormatOptions& options) const override; - Status write_column_to_mysql(const IColumn& column, MysqlRowBuffer& row_buffer, - int row_idx, bool col_const, - const FormatOptions& options) const override; - -private: - template - Status _write_column_to_mysql(const IColumn& column, MysqlRowBuffer& result, - int row_idx, bool col_const, const FormatOptions& options) const; -}; class DataTypeTimeV2SerDe : public DataTypeNumberSerDe { 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 0e567a2b74327a..c2195fd7e69535 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 @@ -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) { 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 2dd71ec31be81f..90221e66c213a9 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(reinterpret_cast(&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(static_cast(column_data.get_element(i)) / (1000 * 1000)); + res_data[i] = cast_set(static_cast(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(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 3f9f378503e611..eaefa3b7658597 100644 --- a/be/src/vec/runtime/time_value.h +++ b/be/src/vec/runtime/time_value.h @@ -56,6 +56,13 @@ class TimeValue { return static_cast(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(value); + } + static std::string to_string(TimeType time, int scale) { return timev2_to_buffer_from_double(time, scale); } @@ -70,6 +77,10 @@ class TimeValue { 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(sec * ONE_SECOND_MICROSECONDS); + } }; } // namespace doris