Mryange commented on code in PR #53659:
URL: https://github.com/apache/doris/pull/53659#discussion_r2359236229
##########
be/src/vec/functions/cast/cast_to_date.h:
##########
@@ -328,6 +329,57 @@ class CastToImpl<CastMode, FromDataType, ToDataType> :
public CastToBase {
col_to->get_data()[i] =
binary_cast<DateV2Value<DateTimeV2ValueType>,
UInt64>(dtmv2);
}
+ } else if constexpr (IsTimeV2Type<FromDataType> &&
IsTimeV2Type<ToDataType>) {
+ const auto* type = assert_cast<const DataTypeTimeV2*>(
+ block.get_by_position(arguments[0]).type.get());
+ auto scale = type->get_scale();
+
+ const auto* to_type = assert_cast<const DataTypeTimeV2*>(
+ block.get_by_position(result).type.get());
+ UInt32 to_scale = to_type->get_scale();
+
+ if (to_scale >= scale) {
+ // nothing to do, just copy
+ col_to->get_data()[i] = col_from->get_data()[i];
+ } else {
+ double time = col_from->get_data()[i];
+ auto sign = TimeValue::sign(time);
+ time = std::abs(time);
+ // e.g. scale reduce to 4, means we need to round the last
2 digits
+ // 999956: 56 > 100/2, then round up to 1000000
+ uint32_t microseconds = TimeValue::microsecond(time);
+ auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
+ uint32_t remainder = microseconds % divisor;
+
+ if (remainder >= divisor / 2) { // need to round up
+ // do rounding up
+ uint32_t rounded_microseconds = ((microseconds /
divisor) + 1) * divisor;
+ // need carry on
+ if (rounded_microseconds >=
TimeValue::ONE_SECOND_MICROSECONDS) {
+ DCHECK(rounded_microseconds ==
TimeValue::ONE_SECOND_MICROSECONDS);
+ time = ((int)time /
TimeValue::ONE_SECOND_MICROSECONDS + 1) *
Review Comment:
time不能转int。尝试用一个800:00:00.000000 的cast,ubsan应该会报错的。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]