Raviston6296 commented on PR #60212: URL: https://github.com/apache/spark/pull/60212#issuecomment-6718450953
LGTM. The truncation precision matches each result type: `ToTime`'s `Invoke` returns `TimeType()`, i.e. `DEFAULT_PRECISION`, and `TimeFromBase` returns `TimeType(MICROS_PRECISION)`. Truncating after the range check in `timeFromSeconds` is what keeps `-0.0000001` an error. Without that, it would become `0` and pass. One observation on the `DOUBLE` overload, non-blocking: truncating `(seconds * NANOS_PER_SECOND).toLong` to microseconds can lose a whole microsecond on values that look exact. For example, `1.000001 * 1e9` is `1000000999.9999999` in double, so `time_from_seconds(CAST(1.000001 AS DOUBLE))` now returns `00:00:01` instead of `00:00:01.000001`. I sampled 200k random microsecond values in `[0, 86400)`, written with 6 fractional digits and parsed as doubles, and about 2.6% end up one microsecond low this way. Before this PR they were 1 ns low, so the stored value differed but still wasn't equal to the intended `TIME(6)`. `timestamp_seconds` does the same `(d * MICROS_PER_SECOND).toLong` truncation and has the same effect (about 1.8% in the same sample), so this is consistent with existing behavior and probably belongs in a separate discussion rather than this PR. Rounding to the nearest microsecond first (`Math.round(seconds * MICROS_PER_SECOND) * NANOS_PER_MICROS`) gave 0 mismatches o n the same sample, if anyone wants to pick that up for both functions. -- 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]
