-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-33863][PYTHON] Respect session timezone in udf workers #53161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[SPARK-33863][PYTHON] Respect session timezone in udf workers #53161
Conversation
|
@cloud-fan , @ueshin , @zhengruifeng we've discussed this but did not reach to a conclusion. I had a draft here and a few questions. We probably need to further discuss about the implementation and implication. |
zhengruifeng
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a behavior change, I think we need a flag for it.
Also we need new tests in test_udf.py
|
|
||
| # Use the local timezone to convert the timestamp | ||
| tz = datetime.datetime.now().astimezone().tzinfo | ||
| tzname = os.environ.get("SPARK_SESSION_LOCAL_TIMEZONE", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To confirm, we will hit this branch for every udf execution, not just once per python worker initialization, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct, but it doesn't seem like spark.session.conf.set("spark.sql.session.timeZone") impacts the result. This only works when I create the session with the conf. Any ideas? I can investigate if that's an issue or we want to understand it. I just thought you might understand immediately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaogaotiantian We can use the same way as the other configs to get the runtime config, like hideTraceback or simplifiedTraceback above. Please take a look at PythonRunner and its subclasses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so basically overwrite this for every subclassed worker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Also if we have a flag, the subclasses should decide whether it returns the session local timezone or None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the flag should be a conf in the same level as session local timezone? Or just Python udf level? Will it be default to the original behavior or the new behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the flag should be the same level as the session local timezone, a runtime conf in SQLConf.
It can be enabled by default, but when disabled, the behavior should be the original behavior.
WDYT? cc @zhengruifeng @HyukjinKwon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Arrow-based UDFs already handles the session local timezone, so it may be ok to just update BasePythonUDFRunner.envVars to have the env var there instead of PythonRunner?
| envVars.put("SPARK_SIMPLIFIED_TRACEBACK", "1") | ||
| } | ||
| if (sessionLocalTimeZone.isDefined) { | ||
| envVars.put("SPARK_SESSION_LOCAL_TIMEZONE", sessionLocalTimeZone.get) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for arrow-based UDFs, sessionLocalTimeZone is actually already passed to the python side
spark/sql/core/src/main/scala/org/apache/spark/sql/execution/python/ArrowPythonRunner.scala
Line 153 in ed23cc3
| val timeZoneConf = Seq(SQLConf.SESSION_LOCAL_TIMEZONE.key -> conf.sessionLocalTimeZone) |
However this workerConf is not available in vanilla Python UDF, probably we can consider supporting it in vanilla Python UDF in the future. also cc @HeartSaVioR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea it's better to pass the configs via a proper protocol, instead of system variables. But it's already the case for vanilla python runner and I think it's fine to follow it.
|
can we add a test which sets |
What changes were proposed in this pull request?
Respect
spark.sql.session.timeZonein UDF workers.This is discussed in #52980 but we decided to move it to a separate PR. There are still open questions left
spark.conf.set. I believe this is trivial to people who are familiar with the configs so I did not investigate too much.Why are the changes needed?
Relying on the timezone of local machine does not make any sense.
Does this PR introduce any user-facing change?
Yes. The UDF behavior regarding to timestamps and timezones will be changed.
How was this patch tested?
Manually
Was this patch authored or co-authored using generative AI tooling?
No