You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "LuciferYang (via GitHub)" <gi...@apache.org> on 2024/04/02 11:50:20 UTC
[PR] [WIP] Refactor the implementation of `SparkDateTimeUtils#toJavaDate` [spark]
LuciferYang opened a new pull request, #45817:
URL: https://github.com/apache/spark/pull/45817
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'common/utils/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
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
Re: [PR] [WIP][SQL] Refactor the implementation of `SparkDateTimeUtils#toJavaDate` [spark]
Posted by "nadavwr (via GitHub)" <gi...@apache.org>.
nadavwr commented on PR #45817:
URL: https://github.com/apache/spark/pull/45817#issuecomment-2291310394
@LuciferYang I'm mostly looking for it to be solved for unit tests. I don't know why reflection would have been necessary in the first place here, so I don't see myself advocating for a PR to drop it -- but I definitely am hoping for it :)
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
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
Re: [PR] [WIP][SQL] Refactor the implementation of `SparkDateTimeUtils#toJavaDate` [spark]
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on PR #45817:
URL: https://github.com/apache/spark/pull/45817#issuecomment-2291395844
That `reflection` is used as a workaround for a cross-compilation testing scenario: maven build or test using Java 21 with `-release 17`.
The specific problem scenario can be reproduced as follows:
1. `git reset --hard 4c1405d10b8fceba7e1486bd4e2e2a24596a71a7`
2. Revert the changes made to `SparkDateTimeUtils `
3. maven build the `sql/api` module of the project using Java 21: `build/mvn clean install -DskipTests -pl sql/api -am`
You may see the compilation exception like:
```
[INFO] compiling 94 Scala sources and 42 Java sources to /spark-source/sql/api/target/scala-2.13/classes ...
[ERROR] [Error] /spark-source/sql/api/src/main/scala/org/apache/spark/sql/catalyst/util/SparkDateTimeUtils.scala:27: object util is not a member of package sun
[ERROR] [Error] /spark-source/sql/api/src/main/scala/org/apache/spark/sql/catalyst/util/SparkDateTimeUtils.scala:218: not found: type ZoneInfo
[ERROR] [Error] /spark-source/sql/api/src/main/scala/org/apache/spark/sql/catalyst/util/SparkDateTimeUtils.scala:218: value getOffsetsByWall is not a member of java.util.TimeZone
[ERROR] [Error] /spark-source/sql/api/src/main/scala/org/apache/spark/sql/catalyst/util/SparkDateTimeUtils.scala:27: Unused import
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=unused-imports, site=org.apache.spark.sql.catalyst.util
[ERROR] four errors found
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Spark Project Parent POM 4.0.0-SNAPSHOT:
[INFO]
[INFO] Spark Project Parent POM ........................... SUCCESS [ 27.177 s]
[INFO] Spark Project Tags ................................. SUCCESS [ 11.821 s]
[INFO] Spark Project Common Utils ......................... SUCCESS [ 12.104 s]
[INFO] Spark Project Variant .............................. SUCCESS [ 3.165 s]
[INFO] Spark Project Unsafe ............................... SUCCESS [ 8.262 s]
[INFO] Spark Project SQL API .............................. FAILURE [ 12.878 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:15 min
[INFO] Finished at: 2024-08-15T22:05:08+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:4.8.1:compile (scala-compile-first) on project spark-sql-api_2.13: Execution scala-compile-first of goal net.alchim31.maven:scala-maven-plugin:4.8.1:compile failed: org.apache.commons.exec.ExecuteException: Process exited with an error: 255 (Exit value: 255) -> [Help 1]
```
So, in order to make this cross-build and testing scenario work normally without changing the original logic, reflection is used there.
The current PR was an attempt I made later, but since I am not very familiar with the background of why special handling for `sun.util.calendar.ZoneInfo` is needed here, I ultimately gave up on this pr.
Additionally, I would like to clarify something regarding ut:
1. If you are executing them using maven or sbt, you do not need to add `--add-opens`.
2. After the merge of [https://github.com/apache/spark/pull/46457](https://github.com/apache/spark/pull/46457), if you are run ut in IDE, there should be no difference from before: you may only need to manually add `--add-opens` to the `VM options` in tests that actually use the `SparkDateTimeUtils#toJavaDate` function(Because Spark 4.0 uses Java 17). This is because the IDE may not necessarily pick up the Java options configured in `pom.xml` or `SparkBuild.scala` correctly.
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
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
Re: [PR] [WIP][SQL] Refactor the implementation of `SparkDateTimeUtils#toJavaDate` [spark]
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #45817:
URL: https://github.com/apache/spark/pull/45817#discussion_r1547730987
##########
sql/api/src/main/scala/org/apache/spark/sql/catalyst/util/SparkDateTimeUtils.scala:
##########
@@ -223,12 +212,7 @@ trait SparkDateTimeUtils {
def toJavaDate(days: Int): Date = {
val rebasedDays = rebaseGregorianToJulianDays(days)
val localMillis = Math.multiplyExact(rebasedDays, MILLIS_PER_DAY)
- val timeZoneOffset = TimeZone.getDefault match {
- case zoneInfo: TimeZone if zoneInfo.getClass.getName == zoneInfoClassName =>
- getOffsetsByWallHandle.invoke(zoneInfo, localMillis, null).asInstanceOf[Int]
- case timeZone: TimeZone =>
- timeZone.getOffset(localMillis - timeZone.getRawOffset)
- }
+ val timeZoneOffset = TimeZone.getDefault.getOffset(localMillis)
Review Comment:
In https://github.com/apache/spark/pull/45716, I replaced the direct call to `sun.util.calendar.ZoneInfo` with the use of `MethodHandle` in order to make Spark 4.0 to be build with `-release`.
However, referring to the `fromJavaDate` function, I wonder if we can directly use `TimeZone.getDefault.getOffset(localMillis)` here?
https://github.com/apache/spark/blob/03f4e45cd7e9e45149b45f3611efd85375e7a327/sql/api/src/main/scala/org/apache/spark/sql/catalyst/util/SparkDateTimeUtils.scala#L193-L198
All unit tests have passed with this pr. Is there any other reason that `sun.util.calendar.ZoneInfo` must be used here?
@hvanhovell @MaxGekk @dongjoon-hyun @HyukjinKwon
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
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
Re: [PR] [WIP][SQL] Refactor the implementation of `SparkDateTimeUtils#toJavaDate` [spark]
Posted by "nadavwr (via GitHub)" <gi...@apache.org>.
nadavwr commented on PR #45817:
URL: https://github.com/apache/spark/pull/45817#issuecomment-2290911169
@LuciferYang If I may ask, why was this PR abandoned? I was hoping to be able to try out the 4.0 preview without --add-opens
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
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
Re: [PR] [WIP][SQL] Refactor the implementation of `SparkDateTimeUtils#toJavaDate` [spark]
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang closed pull request #45817: [WIP][SQL] Refactor the implementation of `SparkDateTimeUtils#toJavaDate`
URL: https://github.com/apache/spark/pull/45817
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
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
Re: [PR] [WIP][SQL] Refactor the implementation of `SparkDateTimeUtils#toJavaDate` [spark]
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #45817:
URL: https://github.com/apache/spark/pull/45817#discussion_r1547732501
##########
sql/api/src/main/scala/org/apache/spark/sql/catalyst/util/SparkDateTimeUtils.scala:
##########
@@ -223,12 +212,7 @@ trait SparkDateTimeUtils {
def toJavaDate(days: Int): Date = {
val rebasedDays = rebaseGregorianToJulianDays(days)
val localMillis = Math.multiplyExact(rebasedDays, MILLIS_PER_DAY)
- val timeZoneOffset = TimeZone.getDefault match {
- case zoneInfo: TimeZone if zoneInfo.getClass.getName == zoneInfoClassName =>
- getOffsetsByWallHandle.invoke(zoneInfo, localMillis, null).asInstanceOf[Int]
- case timeZone: TimeZone =>
- timeZone.getOffset(localMillis - timeZone.getRawOffset)
- }
+ val timeZoneOffset = TimeZone.getDefault.getOffset(localMillis)
Review Comment:
If this is feasible, I will update the PR description later
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
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
Re: [PR] [WIP][SQL] Refactor the implementation of `SparkDateTimeUtils#toJavaDate` [spark]
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on PR #45817:
URL: https://github.com/apache/spark/pull/45817#issuecomment-2290934727
Under normal circumstances, there is no need to add additional `--add-opens` when using `4.0 preview`, because some `--add-opens` will be added by default during the job submission process.
If you are interested in this PR itself, you can try submitting it again :)
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
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