# Parquet时间戳值在Spark或PyArrow中因不同时区设置读取后相差数小时

- **ID:** `data/parquet-timestamp-timezone-mismatch`
- **领域:** data
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Parquet时间戳按约定存储为UTC，但如果会话时区未设置为UTC，读取器（如Spark、PyArrow）可能会应用本地时区转换，导致数小时的误差。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Spark 3.4 | active | — | — |
| PyArrow 12.0 | active | — | — |
| Pandas 2.0 | active | — | — |

## 解决方案

1. ```
   在读取前将Spark会话时区设置为UTC：spark.conf.set('spark.sql.session.timeZone', 'UTC')。
   ```
2. ```
   在PyArrow中，指定时间戳分辨率：pq.read_table('file.parquet', timestamp_as_object=True)并手动转换为UTC。
   ```

## 无效尝试

- **Manually adding or subtracting hours to timestamps after reading** — Hard-coded offsets are fragile and do not account for daylight saving time or varying timezone configurations. (80% 失败率)
- **Converting all timestamps to local time in the source system before writing** — This breaks the UTC convention and causes inconsistent behavior across different readers. (90% 失败率)
