This is an automated email from the ASF dual-hosted git repository. jacktengg pushed a commit to branch dev-timestamp-ns in repository https://gitbox.apache.org/repos/asf/doris.git
commit b073727d9e90ac3abf75134d3450f0fbcd00cd30 Author: jacktengg <[email protected]> AuthorDate: Fri Aug 28 00:25:46 2026 +0800 [improvement](be) Avoid duplicate fractional scaling ### What problem does this PR solve? Issue Number: None Related PR: #66761 Problem Summary: DATETIMEV2 and TIMESTAMP_NS fractional-second parsing scaled short fractional input twice: first to the target scale and then to the result scale. Compute the parsed scale once and apply a single equivalent multiplier while preserving over-scale rounding and second-carry behavior. ### Release note None ### Check List (For Author) - Test: Unit Test - ./build.sh --be - ./run-be-ut.sh --run --filter=DataTypeTimeStampNsTest.ParseAtFixedNanosecondPrecision:CastToStringTest.test -j 49 - Behavior changed: No - Does this need documentation: No --- be/src/exprs/function/cast/cast_to_datetimev2_impl.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/be/src/exprs/function/cast/cast_to_datetimev2_impl.hpp b/be/src/exprs/function/cast/cast_to_datetimev2_impl.hpp index 8bf86ba355d..839afafd6ec 100644 --- a/be/src/exprs/function/cast/cast_to_datetimev2_impl.hpp +++ b/be/src/exprs/function/cast/cast_to_datetimev2_impl.hpp @@ -322,8 +322,10 @@ inline bool CastToDatetimeV2::parse_fractional_seconds(const char* start, size_t DCHECK_LE(to_scale, ResultScale); StringParser::ParseResult success; + const auto parsed_scale = + static_cast<uint32_t>(std::min<size_t>(length, static_cast<size_t>(to_scale))); auto fraction = StringParser::string_to_uint_greedy_no_overflow<uint32_t>( - start, std::min<int>(static_cast<int>(length), static_cast<int>(to_scale)), &success); + start, parsed_scale, &success); SET_PARAMS_RET_FALSE_IFN(success == StringParser::PARSE_SUCCESS, "invalid fractional part in datetime string '{}'", std::string {start, start + length}); @@ -339,11 +341,9 @@ inline bool CastToDatetimeV2::parse_fractional_seconds(const char* start, size_t fraction = 0; } } - } else { - fraction *= common::exp10_i32(to_scale - static_cast<uint32_t>(length)); } - fraction *= common::exp10_i32(ResultScale - to_scale); + fraction *= common::exp10_i32(ResultScale - parsed_scale); if constexpr (is_timestamp_ns_result<ResultType>) { datetime.unchecked_set_time_unit<TimeUnit::MICROSECOND>( fraction / TimeStampNsValue::NANOS_PER_MICROSECOND); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
