You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/05/27 03:39:55 UTC
[GitHub] [spark] MaxGekk opened a new pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
MaxGekk opened a new pull request #28643:
URL: https://github.com/apache/spark/pull/28643
### What changes were proposed in this pull request?
Currently, the legacy fractional formatter is based on the implementation from Spark 2.4 which formats the input timestamp twice:
```
val timestampString = ts.toString
val formatted = legacyFormatter.format(ts)
```
to strip trailing zeros. This PR proposes to avoid the second formatting via `SimpleDateFormat` by stripping `'.0'` directly.
### Why are the changes needed?
It makes legacy fractional formatter faster.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
By existing test "format fraction of second" in `TimestampFormatterSuite` + added test for timestamps before 1970-01-01 00:00:00Z
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634866003
thanks, merging to master!
It's not a perf regression so I didn't backport it to 3.0
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins removed a comment on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-633957223
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins commented on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634659596
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA commented on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634863916
**[Test build #123191 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/123191/testReport)** for PR 28643 at commit [`292311a`](https://github.com/apache/spark/commit/292311a39be3be97c1230e62753e5887c82f1bfd).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins removed a comment on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634865261
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA commented on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-633956755
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins removed a comment on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634851430
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA removed a comment on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-633956755
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #28643:
URL: https://github.com/apache/spark/pull/28643#discussion_r431136998
##########
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:
Does perf matter so much here? It's much simpler to write
```
while (nanos % 10 == 0) {
nanos /= 10
}
formatted + "." + nanos.toString
```
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins commented on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634865261
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins commented on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-633957223
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins removed a comment on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634664400
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins removed a comment on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634659596
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins commented on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634851430
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] MaxGekk commented on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
MaxGekk commented on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634659979
@cloud-fan @HyukjinKwon Please, review this PR.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins commented on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634664400
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] MaxGekk commented on a change in pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan closed pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #28643:
URL: https://github.com/apache/spark/pull/28643
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] MaxGekk commented on a change in pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
MaxGekk commented on a change in pull request #28643:
URL: https://github.com/apache/spark/pull/28643#discussion_r431143795
##########
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:
This code is wrong. For example, if nanos = 000001000. You removed trailing zeros in the loop, and get just `1`. So, the result will be `.1` which is wrong. It should be `.000001`.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA commented on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634658022
**[Test build #123189 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/123189/testReport)** for PR 28643 at commit [`eeff55a`](https://github.com/apache/spark/commit/eeff55ac59b2962805898251c42d2d1f36b2698c).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA removed a comment on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634658022
**[Test build #123189 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/123189/testReport)** for PR 28643 at commit [`eeff55a`](https://github.com/apache/spark/commit/eeff55ac59b2962805898251c42d2d1f36b2698c).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA commented on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634668451
**[Test build #123191 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/123191/testReport)** for PR 28643 at commit [`292311a`](https://github.com/apache/spark/commit/292311a39be3be97c1230e62753e5887c82f1bfd).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA removed a comment on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634668451
**[Test build #123191 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/123191/testReport)** for PR 28643 at commit [`292311a`](https://github.com/apache/spark/commit/292311a39be3be97c1230e62753e5887c82f1bfd).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA commented on pull request #28643: [SPARK-31762][SQL][FOLLOWUP] Avoid double formatting in legacy fractional formatter
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #28643:
URL: https://github.com/apache/spark/pull/28643#issuecomment-634849948
**[Test build #123189 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/123189/testReport)** for PR 28643 at commit [`eeff55a`](https://github.com/apache/spark/commit/eeff55ac59b2962805898251c42d2d1f36b2698c).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org