MaxGekk commented on a change in pull request #28643:
URL: https://github.com/apache/spark/pull/28643#discussion_r431126438
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TimestampFormatter.scala
##########
@@ -127,16 +127,37 @@ class FractionTimestampFormatter(zoneId: ZoneId)
override protected lazy val formatter =
DateTimeFormatterHelper.fractionFormatter
// The new formatter will omit the trailing 0 in the timestamp string, but
the legacy formatter
- // can't. Here we borrow the code from Spark 2.4
DateTimeUtils.timestampToString to omit the
- // trailing 0 for the legacy formatter as well.
+ // can't. Here we use the legacy formatter to format the given timestamp up
to seconds fractions,
+ // and custom implementation to format the fractional part without trailing
zeros.
override def format(ts: Timestamp): String = {
- val timestampString = ts.toString
val formatted = legacyFormatter.format(ts)
-
- if (timestampString.length > 19 && timestampString.substring(19) != ".0") {
- formatted + timestampString.substring(19)
- } else {
+ var nanos = ts.getNanos
+ if (nanos == 0) {
formatted
+ } else {
+ // Formats non-zero seconds fraction w/o trailing zeros. For example:
Review comment:
I borrowed the implementation from JDK 11 java.sql.Timestamp.toString:
https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.sql/share/classes/java/sql/Timestamp.java#L266-L313
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]