This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new b3e28bf071c branch-4.0: [Refactor](function) Remove useless return
type check of unix_timstamp #60042 (#60109)
b3e28bf071c is described below
commit b3e28bf071c211f468ea5bc495dc8b12e297aaf7
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Jan 30 16:20:37 2026 +0800
branch-4.0: [Refactor](function) Remove useless return type check of
unix_timstamp #60042 (#60109)
Cherry-picked from #60042
---------
Co-authored-by: zclllyybb <[email protected]>
---
.../serde/data_type_timestamptz_serde.cpp | 4 +---
be/src/vec/exec/format/column_type_convert.h | 14 +++----------
be/src/vec/functions/function_convert_tz.cpp | 8 ++------
.../vec/functions/function_other_types_to_date.cpp | 23 +++++++++-------------
be/src/vec/runtime/timestamptz_value.h | 4 ++--
be/src/vec/runtime/vdatetime_value.cpp | 20 +++++++++----------
be/src/vec/runtime/vdatetime_value.h | 6 +++---
7 files changed, 29 insertions(+), 50 deletions(-)
diff --git a/be/src/vec/data_types/serde/data_type_timestamptz_serde.cpp
b/be/src/vec/data_types/serde/data_type_timestamptz_serde.cpp
index 5694c7f0472..00d56d96a8e 100644
--- a/be/src/vec/data_types/serde/data_type_timestamptz_serde.cpp
+++ b/be/src/vec/data_types/serde/data_type_timestamptz_serde.cpp
@@ -223,9 +223,7 @@ Status DataTypeTimeStampTzSerDe::write_column_to_orc(const
std::string& timezone
}
int64_t timestamp = 0;
- if (!col_data[row_id].unix_timestamp(×tamp, UTC)) {
- return Status::InternalError("get unix timestamp error.");
- }
+ col_data[row_id].unix_timestamp(×tamp, UTC);
cur_batch->data[row_id] = timestamp;
cur_batch->nanoseconds[row_id] = col_data[row_id].microsecond() *
micro_to_nano_second;
diff --git a/be/src/vec/exec/format/column_type_convert.h
b/be/src/vec/exec/format/column_type_convert.h
index 98dc13f952c..c78e201bb37 100644
--- a/be/src/vec/exec/format/column_type_convert.h
+++ b/be/src/vec/exec/format/column_type_convert.h
@@ -615,7 +615,7 @@ public:
}
size_t rows = from_col->size();
- auto& src_data = static_cast<const
SrcColumnType*>(from_col.get())->get_data();
+ const auto& src_data = static_cast<const
SrcColumnType*>(from_col.get())->get_data();
size_t start_idx = to_col->size();
to_col->resize(start_idx + rows);
auto& data = static_cast<DstColumnType&>(*to_col.get()).get_data();
@@ -625,16 +625,8 @@ public:
auto& dst_value = reinterpret_cast<DstCppType&>(data[start_idx +
i]);
int64_t ts_s = 0;
- if (!src_value.unix_timestamp(&ts_s, cctz::utc_time_zone())) {
- if (null_map == nullptr) {
- char buf[30];
- src_data[i].to_string(buf);
- return Status::InternalError("Failed to cast value '{}' to
{} column", buf,
- dst_col->get_name());
- } else {
- (*null_map)[start_idx + i] = 1;
- }
- }
+ src_value.unix_timestamp(&ts_s, cctz::utc_time_zone());
+
auto micro = src_value.microsecond();
int64_t ts_ms = ts_s * 1000 + micro / 1000;
if constexpr (DstPrimitiveType != TYPE_LARGEINT &&
DstPrimitiveType != TYPE_BIGINT) {
diff --git a/be/src/vec/functions/function_convert_tz.cpp
b/be/src/vec/functions/function_convert_tz.cpp
index 48a33752568..70d5d8bf8b1 100644
--- a/be/src/vec/functions/function_convert_tz.cpp
+++ b/be/src/vec/functions/function_convert_tz.cpp
@@ -243,9 +243,7 @@ private:
DateValueType ts_value2;
std::pair<int64_t, int64_t> timestamp;
- if (!ts_value.unix_timestamp(×tamp, from_tz)) [[unlikely]] {
- throw_invalid_string("convert_tz", from_tz.name());
- }
+ ts_value.unix_timestamp(×tamp, from_tz);
ts_value2.from_unixtime(timestamp, to_tz);
if (!ts_value2.is_valid_date()) [[unlikely]] {
@@ -298,9 +296,7 @@ private:
}
std::pair<int64_t, int64_t> timestamp;
- if (!ts_value.unix_timestamp(×tamp, from_tz)) {
- throw_invalid_string("convert_tz", from_tz.name());
- }
+ ts_value.unix_timestamp(×tamp, from_tz);
ts_value2.from_unixtime(timestamp, to_tz);
if (!ts_value2.is_valid_date()) [[unlikely]] {
diff --git a/be/src/vec/functions/function_other_types_to_date.cpp
b/be/src/vec/functions/function_other_types_to_date.cpp
index ed45de2fa03..5b16f44ce76 100644
--- a/be/src/vec/functions/function_other_types_to_date.cpp
+++ b/be/src/vec/functions/function_other_types_to_date.cpp
@@ -837,18 +837,15 @@ struct UnixTimeStampStrImpl {
}
std::pair<int64_t, int64_t> timestamp {};
- if (!ts_value.unix_timestamp(×tamp,
context->state()->timezone_obj())) {
- // should not happen
- } else {
- auto [sec, ms] = trim_timestamp(timestamp, NewVersion);
- // trailing ms
- auto ms_str = std::to_string(ms).substr(0, 6);
- if (ms_str.empty()) {
- ms_str = "0";
- }
-
- col_result_data[i] = Decimal64::from_int_frac(sec,
std::stoll(ms_str), 6).value;
+ ts_value.unix_timestamp(×tamp,
context->state()->timezone_obj());
+ auto [sec, ms] = trim_timestamp(timestamp, NewVersion);
+ // trailing ms
+ auto ms_str = std::to_string(ms).substr(0, 6);
+ if (ms_str.empty()) {
+ ms_str = "0";
}
+
+ col_result_data[i] = Decimal64::from_int_frac(sec,
std::stoll(ms_str), 6).value;
}
if (null_map_left || null_map_right) {
@@ -973,9 +970,7 @@ public:
reinterpret_cast<const
DateV2Value<DateTimeV2ValueType>&>(*source.data);
const cctz::time_zone& time_zone =
context->state()->timezone_obj();
int64_t timestamp {0};
- auto ret = dt.unix_timestamp(×tamp, time_zone);
- // ret must be true
- DCHECK(ret);
+ dt.unix_timestamp(×tamp, time_zone);
auto microsecond = dt.microsecond();
timestamp = timestamp * Impl::ratio + microsecond / ratio_to_micro;
res_data[i] = timestamp;
diff --git a/be/src/vec/runtime/timestamptz_value.h
b/be/src/vec/runtime/timestamptz_value.h
index a65e95d7ce2..7b7f1139a52 100644
--- a/be/src/vec/runtime/timestamptz_value.h
+++ b/be/src/vec/runtime/timestamptz_value.h
@@ -139,8 +139,8 @@ public:
void set_microsecond(uint64_t microsecond) {
_utc_dt.set_microsecond(microsecond); }
- bool unix_timestamp(int64_t* timestamp, const cctz::time_zone& ctz) const {
- return _utc_dt.unix_timestamp(timestamp, ctz);
+ void unix_timestamp(int64_t* timestamp, const cctz::time_zone& ctz) const {
+ _utc_dt.unix_timestamp(timestamp, ctz);
}
// Convert UTC time to local time based on the given timezone
diff --git a/be/src/vec/runtime/vdatetime_value.cpp
b/be/src/vec/runtime/vdatetime_value.cpp
index da3b2831289..4cf32a0e831 100644
--- a/be/src/vec/runtime/vdatetime_value.cpp
+++ b/be/src/vec/runtime/vdatetime_value.cpp
@@ -1574,14 +1574,14 @@ bool VecDateTimeValue::unix_timestamp(int64_t*
timestamp, const std::string& tim
if (!TimezoneUtils::find_cctz_time_zone(timezone, ctz)) {
return false;
}
- return unix_timestamp(timestamp, ctz);
+ unix_timestamp(timestamp, ctz);
+ return true;
}
-bool VecDateTimeValue::unix_timestamp(int64_t* timestamp, const
cctz::time_zone& ctz) const {
+void VecDateTimeValue::unix_timestamp(int64_t* timestamp, const
cctz::time_zone& ctz) const {
const auto tp =
cctz::convert(cctz::civil_second(_year, _month, _day, _hour,
_minute, _second), ctz);
*timestamp = tp.time_since_epoch().count();
- return true;
}
bool VecDateTimeValue::from_unixtime(int64_t timestamp, const std::string&
timezone) {
@@ -2778,11 +2778,12 @@ bool DateV2Value<T>::unix_timestamp(int64_t* timestamp,
const std::string& timez
if (!TimezoneUtils::find_cctz_time_zone(timezone, ctz)) {
return false;
}
- return unix_timestamp(timestamp, ctz);
+ unix_timestamp(timestamp, ctz);
+ return true;
}
template <typename T>
-bool DateV2Value<T>::unix_timestamp(int64_t* timestamp, const cctz::time_zone&
ctz) const {
+void DateV2Value<T>::unix_timestamp(int64_t* timestamp, const cctz::time_zone&
ctz) const {
if constexpr (is_datetime) {
const auto tp =
cctz::convert(cctz::civil_second(date_v2_value_.year_,
date_v2_value_.month_,
@@ -2790,14 +2791,12 @@ bool DateV2Value<T>::unix_timestamp(int64_t* timestamp,
const cctz::time_zone& c
date_v2_value_.minute_,
date_v2_value_.second_),
ctz);
*timestamp = tp.time_since_epoch().count();
- return true;
} else {
const auto tp =
cctz::convert(cctz::civil_second(date_v2_value_.year_,
date_v2_value_.month_,
date_v2_value_.day_, 0, 0, 0),
ctz);
*timestamp = tp.time_since_epoch().count();
- return true;
}
}
@@ -2808,11 +2807,12 @@ bool DateV2Value<T>::unix_timestamp(std::pair<int64_t,
int64_t>* timestamp,
if (!TimezoneUtils::find_cctz_time_zone(timezone, ctz)) {
return false;
}
- return unix_timestamp(timestamp, ctz);
+ unix_timestamp(timestamp, ctz);
+ return true;
}
template <typename T>
-bool DateV2Value<T>::unix_timestamp(std::pair<int64_t, int64_t>* timestamp,
+void DateV2Value<T>::unix_timestamp(std::pair<int64_t, int64_t>* timestamp,
const cctz::time_zone& ctz) const {
DCHECK(is_datetime) << "Function unix_timestamp with double_t timestamp
only support "
"datetimev2 value type.";
@@ -2824,9 +2824,7 @@ bool DateV2Value<T>::unix_timestamp(std::pair<int64_t,
int64_t>* timestamp,
ctz);
timestamp->first = tp.time_since_epoch().count();
timestamp->second = date_v2_value_.microsecond_;
- } else { // just make compiler happy
}
- return true;
}
template <typename T>
diff --git a/be/src/vec/runtime/vdatetime_value.h
b/be/src/vec/runtime/vdatetime_value.h
index 30a70926e39..a9ff6503ddf 100644
--- a/be/src/vec/runtime/vdatetime_value.h
+++ b/be/src/vec/runtime/vdatetime_value.h
@@ -590,7 +590,7 @@ public:
//unix_timestamp is called with a timezone argument,
//it returns seconds of the value of date literal since '1970-01-01
00:00:00' UTC
bool unix_timestamp(int64_t* timestamp, const std::string& timezone) const;
- bool unix_timestamp(int64_t* timestamp, const cctz::time_zone& ctz) const;
+ void unix_timestamp(int64_t* timestamp, const cctz::time_zone& ctz) const;
//construct datetime_value from timestamp and timezone
//timestamp is an internal timestamp value representing seconds since
'1970-01-01 00:00:00' UTC. negative avaliable.
@@ -1100,10 +1100,10 @@ public:
//unix_timestamp is called with a timezone argument,
//it returns seconds of the value of date literal since '1970-01-01
00:00:00' UTC
bool unix_timestamp(int64_t* timestamp, const std::string& timezone) const;
- bool unix_timestamp(int64_t* timestamp, const cctz::time_zone& ctz) const;
+ void unix_timestamp(int64_t* timestamp, const cctz::time_zone& ctz) const;
//the first arg is result of fixed point
bool unix_timestamp(std::pair<int64_t, int64_t>* timestamp, const
std::string& timezone) const;
- bool unix_timestamp(std::pair<int64_t, int64_t>* timestamp, const
cctz::time_zone& ctz) const;
+ void unix_timestamp(std::pair<int64_t, int64_t>* timestamp, const
cctz::time_zone& ctz) const;
//construct datetime_value from timestamp and timezone
//timestamp is an internal timestamp value representing seconds since
'1970-01-01 00:00:00' UTC. negative avaliable.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]