TIMESTAMP_EPOCH_UNIT_MISMATCH
data
type_error
ai_generated
true
时间戳反序列化失败,因为纪元以毫秒为单位但预期是秒
Timestamp deserialization fails because epoch is in milliseconds but expected in seconds
ID: data/timestamp-epoch-millis-vs-seconds
90%修复率
89%置信度
1证据数
2024-06-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Apache Kafka 3.5.0 | active | — | — | — |
| Python datetime 3.11 | active | — | — | — |
| Java 17 | active | — | — | — |
根因分析
数据源提供Unix纪元毫秒的时间戳(如1700000000000),但反序列化器期望秒(如1700000000),导致溢出或错误日期。
English
The data source provides timestamps as Unix epoch milliseconds (e.g., 1700000000000) but the deserializer expects seconds (e.g., 1700000000), causing overflow or incorrect dates.
官方文档
https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html解决方案
-
Detect the unit by checking the magnitude: if timestamp > 1e12, treat as milliseconds and divide by 1000. Example in Python: `if ts > 1e12: ts /= 1000`.
-
Configure the deserializer to expect milliseconds explicitly, e.g., in Kafka Connect: `timestamp.converter=org.apache.kafka.connect.json.JsonConverter` with `converter.type=timestamp` and `converter.format=epoch.millis`.
无效尝试
常见但无效的做法:
-
70% 失败
Dividing by 1000 in code may cause integer overflow if the timestamp is stored as a 32-bit integer.
-
80% 失败
Assuming all timestamps are in milliseconds may break when some sources use seconds.