Skip to content

[SPARK-27031][SQL] Avoid double formatting in timestampToString#23936

Closed
MaxGekk wants to merge 5 commits intoapache:masterfrom
MaxGekk:timestamp-to-string
Closed

[SPARK-27031][SQL] Avoid double formatting in timestampToString#23936
MaxGekk wants to merge 5 commits intoapache:masterfrom
MaxGekk:timestamp-to-string

Conversation

@MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Mar 2, 2019

What changes were proposed in this pull request?

Removed unnecessary conversion of microseconds in DateTimeUtils.timestampToString to java.sql.Timestamp which aims to output fraction of seconds by casting it to string. This was replaced by special TimestampFormatter which appends the fraction formatter to DateTimeFormatterBuilder: appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true). The former one means trailing zeros in second's fraction should be truncated while formatting.

How was this patch tested?

By existing test suites like CastSuite, DateTimeUtilsSuite, JDBCSuite, and by new test in TimestampFormatterSuite.

Copy link
Member

@srowen srowen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable, and I think you know this part better than anyone. Is there any behavior change?

@SparkQA
Copy link

SparkQA commented Mar 2, 2019

Test build #102938 has finished for PR 23936 at commit 09a9f54.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@MaxGekk
Copy link
Member Author

MaxGekk commented Mar 2, 2019

Is there any behavior change?

I believe there shouldn't be.

@SparkQA
Copy link

SparkQA commented Mar 2, 2019

Test build #102940 has finished for PR 23936 at commit ff68c90.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

}

def getFractionFormatter(timeZone: TimeZone): TimestampFormatter = {
apply(DateTimeFormatterHelper.fractionPattern, timeZone, defaultLocale)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, last nit then: this should probably use the naming convention for constants, FRACTION_PATTERN.
How about just a method to return this formatter, rather than a special constant that causes another method to return it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it makes sense to inherit from Iso8601TimestampFormatter and override formatter. I will try and see how it will look like.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done this. Please, take a look at the last commit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to support only one locale Locale.US but I think it is ok for this case. If we will need the fraction formatter for multiple locales, we can come back to the original solution with caching.

@SparkQA
Copy link

SparkQA commented Mar 4, 2019

Test build #103000 has finished for PR 23936 at commit 23d4eac.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • class FractionTimestampFormatter(timeZone: TimeZone)

@SparkQA
Copy link

SparkQA commented Mar 4, 2019

Test build #4592 has finished for PR 23936 at commit 23d4eac.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • class FractionTimestampFormatter(timeZone: TimeZone)

}
}

class FractionTimestampFormatter(timeZone: TimeZone)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, last nit. Can you add some docs here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@SparkQA
Copy link

SparkQA commented Mar 5, 2019

Test build #103052 has finished for PR 23936 at commit d2b2b74.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@srowen
Copy link
Member

srowen commented Mar 6, 2019

Merged to master

@srowen srowen closed this in 9b55722 Mar 6, 2019
@MaxGekk MaxGekk deleted the timestamp-to-string branch September 18, 2019 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants