Uh oh!
There was an error while loading. Please reload this page.
[SPARK-28141][SQL] Support special date values - #25708
Conversation
SparkQA
commented
Sep 6, 2019
Test build #110230 has finished for PR 25708 at commit
|
| assert(toDate("epoch", zoneId).get === 0) | ||
| val today = localDateToDays(LocalDate.now(zoneId)) | ||
| assert(toDate("yesterday", zoneId).get === today - 1) |
There was a problem hiding this comment.
Here, there is the risk that today contains previous day if we were unlucky and the test was executed at the end of the day. Maybe, need to introduce some tolerance.
SparkQA
commented
Sep 6, 2019
Test build #110236 has finished for PR 25708 at commit
|
…ecial-values # Conflicts: # sql/core/src/test/resources/sql-tests/results/pgSQL/date.sql.out
SparkQA
commented
Sep 6, 2019
Test build #110255 has finished for PR 25708 at commit
|
SparkQA
commented
Sep 6, 2019
Test build #110258 has finished for PR 25708 at commit
|
MaxGekk
commented
Sep 7, 2019
@dongjoon-hyun@maropu@cloud-fan Please, review the PR. |
Uh oh!
There was an error while loading. Please reload this page.
SparkQA
commented
Sep 7, 2019
Test build #110285 has finished for PR 25708 at commit
|
maropu
commented
Sep 8, 2019
The other DBMS-like systems support these syntaxes? If not, we should turn on/off these features by the compatibility mode flag https://issues.apache.org/jira/browse/SPARK-28934? |
maropu
commented
Sep 8, 2019
|
| case _ => | ||
| (c, evPrim, evNull) => code"$evNull = true;" | ||
| } | ||
| } |
There was a problem hiding this comment.
Just put the gen'd code for other reviewers;
/* 051 */ boolean project_isNull_0 = columnartorow_isNull_0;
/* 052 */ int project_value_0 = -1;
/* 053 */ if (!columnartorow_isNull_0) {
/* 054 */ scala.Option<Integer> project_intOpt_0 =
/* 055 */ org.apache.spark.sql.catalyst.util.DateTimeUtils.stringToDate(columnartorow_value_0, ((java.time.ZoneId) references[2] /* zoneId */));
/* 056 */ if (project_intOpt_0.isDefined()) {
/* 057 */ project_value_0 = ((Integer) project_intOpt_0.get()).intValue();
/* 058 */ } else {
/* 059 */ project_isNull_0 = true;
/* 060 */ }
/* 061 */ }
| val zid = getZoneId() | ||
| (c, evPrim, evNull) => | ||
| code""" | ||
| scala.Option<Integer> $intOpt = |
There was a problem hiding this comment.
btw, (this is not related to this pr though), scala.Option<Integer> is ok for java compilers/jvm? @rednaxelafx I remember that jdk compilers cannot compile this statement: #21770 (comment) because it seems the compilers erase the returned type from scala.Option<Integer> to scala.Option<Object>. I'm not sure why janino accepts this though....
SparkQA
commented
Sep 10, 2019
Test build #110409 has finished for PR 25708 at commit
|
maropu
commented
Sep 10, 2019
retest this please |
SparkQA
commented
Sep 10, 2019
Test build #110417 has finished for PR 25708 at commit
|
MaxGekk
commented
Sep 12, 2019
@maropu@dongjoon-hyun Here is the same question as in #25716 (comment) |
…ecial-values # Conflicts: # sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala # sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeUtilsSuite.scala # sql/core/src/test/scala/org/apache/spark/sql/CsvFunctionsSuite.scala # sql/core/src/test/scala/org/apache/spark/sql/JsonFunctionsSuite.scala
SparkQA
commented
Sep 18, 2019
Test build #110922 has finished for PR 25708 at commit
|
MaxGekk
commented
Sep 19, 2019
I have rebased this on the master with merged #25716 . @HyukjinKwon Could you take a look at this, please. |
MaxGekk
commented
Sep 20, 2019
@dongjoon-hyun@maropu@HyukjinKwon Could take a look at this PR which is similar to already merged changes for the timestamp type. |
maropu
left a comment
There was a problem hiding this comment.
Looks nice cc: @HyukjinKwon@dongjoon-hyun
HyukjinKwon
commented
Sep 22, 2019
I am merging this just to unblock and easier to work further but please make sure to have a flag. Seems like that's pointed out by multiple committers such as @maropu and @cloud-fan. |
HyukjinKwon
commented
Sep 22, 2019
Otherwise, I will revert this and #25716 Merged to master. |
maropu
commented
Sep 22, 2019
We already have a jira ticket for linking this feature to the flag? |
MaxGekk
commented
Sep 22, 2019
This PR #25834 hides the feature under the SQL config spark.sql.dialect = "PostgreSQL" |
maropu
commented
Sep 22, 2019
Oh, I see. Thanks! |
… SQL migration guide ### What changes were proposed in this pull request? Updated the SQL migration guide regarding to recently supported special date and timestamp values, see #25716 and #25708. Closes#25834 ### Why are the changes needed? To let users know about new feature in Spark 3.0. ### Does this PR introduce any user-facing change? No Closes#25948 from MaxGekk/special-values-migration-guide. Authored-by: Maxim Gekk <max.gekk@gmail.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
…only ### What changes were proposed in this pull request? In the PR, I propose to support special datetime values introduced by #25708 and by #25716 only in typed literals, and don't recognize them in parsing strings to dates/timestamps. The following string values are supported only in typed timestamp literals: - `epoch [zoneId]` - `1970-01-01 00:00:00+00 (Unix system time zero)` - `today [zoneId]` - midnight today. - `yesterday [zoneId]` - midnight yesterday - `tomorrow [zoneId]` - midnight tomorrow - `now` - current query start time. For example: ```sql spark-sql> SELECT timestamp 'tomorrow'; 2019-09-07 00:00:00 ``` Similarly, the following special date values are supported only in typed date literals: - `epoch [zoneId]` - `1970-01-01` - `today [zoneId]` - the current date in the time zone specified by `spark.sql.session.timeZone`. - `yesterday [zoneId]` - the current date -1 - `tomorrow [zoneId]` - the current date + 1 - `now` - the date of running the current query. It has the same notion as `today`. For example: ```sql spark-sql> SELECT date 'tomorrow' - date 'yesterday'; 2 ``` ### Why are the changes needed? In the current implementation, Spark supports the special date/timestamp value in any input strings casted to dates/timestamps that leads to the following problems: - If executors have different system time, the result is inconsistent, and random. Column values depend on where the conversions were performed. - The special values play the role of distributed non-deterministic functions though users might think of the values as constants. ### Does this PR introduce _any_ user-facing change? Yes but the probability should be small. ### How was this patch tested? By running existing test suites: ``` $ build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z interval.sql" $ build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z date.sql" $ build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z timestamp.sql" $ build/sbt "test:testOnly *DateTimeUtilsSuite" ``` Closes#32714 from MaxGekk/remove-datetime-special-values. Lead-authored-by: Max Gekk <max.gekk@gmail.com> Co-authored-by: Maxim Gekk <max.gekk@gmail.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
What changes were proposed in this pull request?
Supported special string values for
DATEtype. They are simply notational shorthands that will be converted to ordinary date values when read. The following string values are supported:epoch [zoneId]-1970-01-01today [zoneId]- the current date in the time zone specified byspark.sql.session.timeZone.yesterday [zoneId]- the current date -1tomorrow [zoneId]- the current date + 1now- the date of running the current query. It has the same notion astoday.For example:
Why are the changes needed?
To maintain feature parity with PostgreSQL, see 8.5.1.4. Special Values
Does this PR introduce any user-facing change?
Previously, the parser fails on the special values with the error:
After the changes, the special values are converted to appropriate dates:
How was this patch tested?
DateFormatterSuiteto check parsing special values from regular strings.DateTimeUtilsSuitecheck parsing those values fromUTF8Stringdate.sql