Uh oh!
There was an error while loading. Please reload this page.
[SPARK-26424][SQL] Use java.time API in date/timestamp expressions - #23358
[SPARK-26424][SQL] Use java.time API in date/timestamp expressions#23358MaxGekk wants to merge 25 commits into
Conversation
SparkQA
commented
Dec 21, 2018
Test build #100346 has finished for PR 23358 at commit
|
Uh oh!
There was an error while loading. Please reload this page.
SparkQA
commented
Dec 21, 2018
Test build #100363 has finished for PR 23358 at commit
|
SparkQA
commented
Dec 21, 2018
Test build #100369 has finished for PR 23358 at commit
|
| .parseCaseInsensitive() | ||
| .appendPattern(pattern) | ||
| .parseDefaulting(ChronoField.YEAR_OF_ERA, 1970) | ||
| .parseDefaulting(ChronoField.ERA, 1) |
There was a problem hiding this comment.
Era is required in STRICT mode
There was a problem hiding this comment.
is 1 a reasonable default value for ERA?
There was a problem hiding this comment.
I think so. This is our current era: https://docs.oracle.com/javase/8/docs/api/java/time/temporal/ChronoField.html#ERA : "The value of the era that was active on 1970-01-01 (ISO) must be assigned the value 1."
| new DateTimeFormatterBuilder() | ||
| .parseCaseInsensitive() | ||
| .appendPattern(pattern) | ||
| .parseDefaulting(ChronoField.YEAR_OF_ERA, 1970) |
There was a problem hiding this comment.
Year must always present in timestamps/dates. Probability of an user is satisfied to default value 1970 is pretty low. Don't think if the user wants to parse let's say 14 Nov, he/she means 14 Nov 1970. I would guess current year but this approach is error prone.
| .parseDefaulting(ChronoField.ERA, 1) | ||
| .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1) | ||
| .parseDefaulting(ChronoField.DAY_OF_MONTH, 1) | ||
| .parseDefaulting(ChronoField.HOUR_OF_DAY, 0) |
There was a problem hiding this comment.
Hours must always present in the time part. The default value causes conflict if the timestamp pattern has a (AM or PM). If there are no hours, we set the time part to zero later.
Uh oh!
There was an error while loading. Please reload this page.
| protected def toInstantWithZoneId(temporalAccessor: TemporalAccessor, zoneId: ZoneId): Instant = { | ||
| val localDateTime = LocalDateTime.from(temporalAccessor) | ||
| val localTime = if (temporalAccessor.query(TemporalQueries.localTime) == null) { |
There was a problem hiding this comment.
If parsed timestamp does not have the time part at all, set all (hours, minutes, seconds and etc.) to zeros.
| */ | ||
| @throws(classOf[ParseException]) | ||
| @throws(classOf[DateTimeParseException]) | ||
| @throws(classOf[DateTimeException]) |
There was a problem hiding this comment.
This annotations are required in whole stage codegen otherwise I got an error about some exception catches are not reachable/used.
| locale: Locale) extends TimestampFormatter with DateTimeFormatterHelper { | ||
| private val formatter = buildFormatter(pattern, locale) | ||
| @transient | ||
| private lazy val formatter = buildFormatter(pattern, locale) |
There was a problem hiding this comment.
The Iso8601TimestampFormatter class became serializable but the build is still not.
Uh oh!
There was an error while loading. Please reload this page.
| import org.apache.spark.sql.internal.SQLConf | ||
| sealed trait TimestampFormatter { | ||
| sealed trait TimestampFormatter extends Serializable { |
There was a problem hiding this comment.
Making it serializable otherwise I got task not serializable exception from generated code
Uh oh!
There was an error while loading. Please reload this page.
SparkQA
commented
Dec 21, 2018
Test build #100371 has finished for PR 23358 at commit
|
MaxGekk
commented
Dec 21, 2018
jenkins, retest this, please |
SparkQA
commented
Dec 22, 2018
Test build #100398 has finished for PR 23358 at commit
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
MaxGekk
commented
Dec 24, 2018
As @hvanhovell mentioned offline, the implementation based on java.time classes changes behavior since it uses IsoChronology which is actually Proleptic Gregorian calendar. It could cause some problems in manipulating old dates. I am going to mention that in the migration guide. I think we can support other calendars like Julian calendar the future by using libraries like ThreeTen-Extra. |
MaxGekk
commented
Dec 24, 2018
R build failed: |
MaxGekk
commented
Dec 24, 2018
jenkins, retest this, please |
SparkQA
commented
Dec 24, 2018
Test build #100419 has finished for PR 23358 at commit
|
SparkQA
commented
Dec 24, 2018
Test build #100424 has finished for PR 23358 at commit
|
SparkQA
commented
Dec 24, 2018
Test build #100426 has finished for PR 23358 at commit
|
cloud-fan
commented
Dec 25, 2018
The migration guide update LGTM. Do we have an example to show the calendar problem? AFAIK SQL standard follows Gregorian calendar, so we shouldn't support Julian calendar. |
MaxGekk
commented
Dec 25, 2018
cloud-fan
commented
Dec 26, 2018
LGTM |
cloud-fan
commented
Dec 27, 2018
thanks, merging to master! |
dongjoon-hyun
commented
Dec 28, 2018
## What changes were proposed in this pull request? In the PR, I propose to switch the `DateFormatClass`, `ToUnixTimestamp`, `FromUnixTime`, `UnixTime` on java.time API for parsing/formatting dates and timestamps. The API has been already implemented by the `Timestamp`/`DateFormatter` classes. One of benefit is those classes support parsing timestamps with microsecond precision. Old behaviour can be switched on via SQL config: `spark.sql.legacy.timeParser.enabled` (`false` by default). ## How was this patch tested? It was tested by existing test suites - `DateFunctionsSuite`, `DateExpressionsSuite`, `JsonSuite`, `CsvSuite`, `SQLQueryTestSuite` as well as PySpark tests. Closesapache#23358 from MaxGekk/new-time-cast. Lead-authored-by: Maxim Gekk <maxim.gekk@databricks.com> Co-authored-by: Maxim Gekk <max.gekk@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
## What changes were proposed in this pull request? This PR fixes the codegen bug introduced by apache#23358 . - https://amplab.cs.berkeley.edu/jenkins/view/Spark%20QA%20Test%20(Dashboard)/job/spark-master-test-maven-hadoop-2.7-ubuntu-scala-2.11/158/ ``` Line 44, Column 93: A method named "apply" is not declared in any enclosing class nor any supertype, nor through a static import ``` ## How was this patch tested? Manual. `DateExpressionsSuite` should be passed with Scala-2.11. Closesapache#23394 from dongjoon-hyun/SPARK-26424. Authored-by: Dongjoon Hyun <dongjoon@apache.org> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
## What changes were proposed in this pull request? In the PR, I propose to switch the `DateFormatClass`, `ToUnixTimestamp`, `FromUnixTime`, `UnixTime` on java.time API for parsing/formatting dates and timestamps. The API has been already implemented by the `Timestamp`/`DateFormatter` classes. One of benefit is those classes support parsing timestamps with microsecond precision. Old behaviour can be switched on via SQL config: `spark.sql.legacy.timeParser.enabled` (`false` by default). ## How was this patch tested? It was tested by existing test suites - `DateFunctionsSuite`, `DateExpressionsSuite`, `JsonSuite`, `CsvSuite`, `SQLQueryTestSuite` as well as PySpark tests. Closesapache#23358 from MaxGekk/new-time-cast. Lead-authored-by: Maxim Gekk <maxim.gekk@databricks.com> Co-authored-by: Maxim Gekk <max.gekk@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
## What changes were proposed in this pull request? This PR fixes the codegen bug introduced by apache#23358 . - https://amplab.cs.berkeley.edu/jenkins/view/Spark%20QA%20Test%20(Dashboard)/job/spark-master-test-maven-hadoop-2.7-ubuntu-scala-2.11/158/ ``` Line 44, Column 93: A method named "apply" is not declared in any enclosing class nor any supertype, nor through a static import ``` ## How was this patch tested? Manual. `DateExpressionsSuite` should be passed with Scala-2.11. Closesapache#23394 from dongjoon-hyun/SPARK-26424. Authored-by: Dongjoon Hyun <dongjoon@apache.org> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>

What changes were proposed in this pull request?
In the PR, I propose to switch the
DateFormatClass,ToUnixTimestamp,FromUnixTime,UnixTimeon java.time API for parsing/formatting dates and timestamps. The API has been already implemented by theTimestamp/DateFormatterclasses. One of benefit is those classes support parsing timestamps with microsecond precision. Old behaviour can be switched on via SQL config:spark.sql.legacy.timeParser.enabled(falseby default).How was this patch tested?
It was tested by existing test suites -
DateFunctionsSuite,DateExpressionsSuite,JsonSuite,CsvSuite,SQLQueryTestSuiteas well as PySpark tests.