Skip to content

Conversation

@ueshin
Copy link
Member

@ueshin ueshin commented Nov 1, 2025

What changes were proposed in this pull request?

Adds timezone to make the timestamp in the log record JSON string the absolute time.

Why are the changes needed?

Without the timezone, the timestamp of each log record doesn't reflect the session timezone, which makes it confusing.

example
>>> from pyspark.sql.functions import *
>>> import logging
>>>
>>> @udf
... def logging_test_udf(x):
...     logger = logging.getLogger("test")
...     logger.warning(f"message")
...     return str(x)
...
>>>
>>> spark.conf.set("spark.sql.pyspark.worker.logging.enabled", True)
>>>
>>> spark.range(1).select(logging_test_udf("id")).show()
...
  • Before
>>> spark.conf.get('spark.sql.session.timeZone')
'America/Los_Angeles'
>>> spark.sql("select ts from system.session.python_worker_logs").show(truncate=False)
+--------------------------+
|ts                        |
+--------------------------+
|2025-10-31 17:17:59.495541|
+--------------------------+

>>> spark.conf.set('spark.sql.session.timeZone', 'UTC')
>>> spark.sql("select ts from system.session.python_worker_logs").show(truncate=False)
+--------------------------+
|ts                        |
+--------------------------+
|2025-10-31 17:17:59.495541|
+--------------------------+
  • After
>>> spark.conf.get('spark.sql.session.timeZone')
'America/Los_Angeles'
>>> spark.sql("select ts from system.session.python_worker_logs").show(truncate=False)
+--------------------------+
|ts                        |
+--------------------------+
|2025-10-31 17:19:52.152868|
+--------------------------+

>>> spark.conf.set('spark.sql.session.timeZone', 'UTC')
>>> spark.sql("select ts from system.session.python_worker_logs").show(truncate=False)
+--------------------------+
|ts                        |
+--------------------------+
|2025-11-01 00:19:52.152868|
+--------------------------+

Does this PR introduce any user-facing change?

Yes, the timestamp of log record is now absolute time.

How was this patch tested?

Manually.

Was this patch authored or co-authored using generative AI tooling?

No.

@HyukjinKwon
Copy link
Member

Merged to master and branch-4.1.

HyukjinKwon pushed a commit that referenced this pull request Nov 2, 2025
…time

### What changes were proposed in this pull request?

Adds timezone to make the timestamp in the log record JSON string the absolute time.

### Why are the changes needed?

Without the timezone, the timestamp of each log record doesn't reflect the session timezone, which makes it confusing.

<details>
<summary>example</summary>

```python
>>> from pyspark.sql.functions import *
>>> import logging
>>>
>>> udf
... def logging_test_udf(x):
...     logger = logging.getLogger("test")
...     logger.warning(f"message")
...     return str(x)
...
>>>
>>> spark.conf.set("spark.sql.pyspark.worker.logging.enabled", True)
>>>
>>> spark.range(1).select(logging_test_udf("id")).show()
...
```

</details>

- Before

```python
>>> spark.conf.get('spark.sql.session.timeZone')
'America/Los_Angeles'
>>> spark.sql("select ts from system.session.python_worker_logs").show(truncate=False)
+--------------------------+
|ts                        |
+--------------------------+
|2025-10-31 17:17:59.495541|
+--------------------------+

>>> spark.conf.set('spark.sql.session.timeZone', 'UTC')
>>> spark.sql("select ts from system.session.python_worker_logs").show(truncate=False)
+--------------------------+
|ts                        |
+--------------------------+
|2025-10-31 17:17:59.495541|
+--------------------------+
```

- After

```python
>>> spark.conf.get('spark.sql.session.timeZone')
'America/Los_Angeles'
>>> spark.sql("select ts from system.session.python_worker_logs").show(truncate=False)
+--------------------------+
|ts                        |
+--------------------------+
|2025-10-31 17:19:52.152868|
+--------------------------+

>>> spark.conf.set('spark.sql.session.timeZone', 'UTC')
>>> spark.sql("select ts from system.session.python_worker_logs").show(truncate=False)
+--------------------------+
|ts                        |
+--------------------------+
|2025-11-01 00:19:52.152868|
+--------------------------+
```

### Does this PR introduce _any_ user-facing change?

Yes, the timestamp of log record is now absolute time.

### How was this patch tested?

Manually.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #52823 from ueshin/issues/SPARK-54123/timezone.

Authored-by: Takuya Ueshin <ueshin@databricks.com>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
(cherry picked from commit e837ff9)
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants