Repository navigation
Description
Description
JSON_ARRAYAGG and JSON_OBJECTAGG serialize TIMESTAMP from its UTC storage representation instead of the value in the current session time zone. The resulting JSON contains a literal UTC suffix and does not change after time_zone changes, while the source TIMESTAMP and scalar JSON constructors do change correctly.
Environment
- Branch:
main - Commit:
0c3a04f390adaf6281fd592a49778ea5b1155e67 - Deployment: local standalone MatrixOne, 1 CN / 1 TN / 1 LogService
- Reference: local MySQL
8.0.45
Steps to reproduce
CREATE DATABASE json_timestamp_agg_repro;
USE json_timestamp_agg_repro;
SET time_zone = '+00:00';
CREATE TABLE t (k VARCHAR(16), ts TIMESTAMP(6));
INSERT INTO t VALUES ('a', '2024-02-29 04:34:56.123456');
SET time_zone = '+08:00';
SELECT ts,
JSON_UNQUOTE(JSON_EXTRACT(JSON_OBJECT('ts', ts), '$.ts')) AS scalar_json,
JSON_UNQUOTE(JSON_EXTRACT(JSON_ARRAYAGG(ts), '$[0]')) AS array_agg,
JSON_UNQUOTE(JSON_EXTRACT(JSON_OBJECTAGG(k, ts), '$.a')) AS object_agg
FROM t
GROUP BY ts;MatrixOne result
ts 2024-02-29 12:34:56.123456
scalar_json 2024-02-29 12:34:56.123456
array_agg 2024-02-29 04:34:56.123456 UTC
object_agg 2024-02-29 04:34:56.123456 UTC
At time_zone='+00:00', both aggregate values are still emitted with the extra UTC suffix. At +08:00, they continue to expose the UTC value instead of the session-local value.
MySQL 8.0.45 result
At +08:00, all four values are:
2024-02-29 12:34:56.123456
At +00:00, all four values are 2024-02-29 04:34:56.123456. MySQL JSON aggregation follows the same session-time-zone conversion as the TIMESTAMP column and scalar JSON constructor.
Scope and repeatability
- Both time zones reproduce identically in three independent MatrixOne runs and three MySQL control runs.
JSON_ARRAYAGGandJSON_OBJECTAGGare both affected.- CTAS persists the UTC-suffixed value; changing the time zone before reading cannot recover the intended session-local JSON value.
- Views and prepared statements reproduce the same aggregate value.
- The source TIMESTAMP, scalar
JSON_OBJECT, NULL handling, table contents, and server availability remain correct.
Code analysis
pkg/sql/colexec/aggexec/jsonagg2.go converts aggregate TIMESTAMP inputs through types.Timestamp.String(). That formats the internal UTC representation and bypasses the session-time-zone-aware conversion used by scalar JSON constructors. The special JSON_ARRAYAGG typed-conversion helper currently includes TIME, DATETIME, and YEAR but explicitly omits TIMESTAMP; JSON_OBJECTAGG does not use the helper at all.
Expected behavior
JSON aggregates should serialize TIMESTAMP values in the current session time zone, without an implementation-specific UTC suffix, consistently with ordinary TIMESTAMP reads, scalar JSON constructors, and MySQL 8. The same conversion must apply to normal, parallel/merge, spill, window, CTAS/view, and prepared paths.
Activity
docs/test: cover temporal compatibility exceptions (#29683)
Ariznawlll commentedon Nov 29, 2026
结论
测试通过。JSON_ARRAYAGG/JSON_OBJECTAGG 现在按执行时会话时区输出 TIMESTAMP,不再固定使用 UTC 或追加 UTC 后缀。
关键证据
版本与环境
922815d74fe664dc9f4ea7bfc4c4e8ac3b279cd0;本次 Linux CI 从官方 main 检出的实际版本为231b68c2d6421e9d212538866e0f825afd6c13e8,两处分别核对完整git_version()。CI 比本地多了 Release merge spill buffers on panic #32160,核对差异仅为 spill sinker 及其两个测试文件。以下 CI 的正式 SQL、SDK 和源码测试确实在 CI 版本上重新执行;不把 MOTR commit 当作 MO 版本,也不将 main 结果外推为 4.2-dev 通过。步骤、断言与实际结果
原值 UTC
2024-02-29 04:34:56.123456,+08:00 聚合返回2024-02-29 12:34:56.123456;-05:30 返回2024-02-28 23:04:56.123456,切回 UTC 恢复原值。TestAccountedJSONAggregatesLifecycleAndSpill包含 array/object TIMESTAMP 时区边界和真实 spill state 编解码;其余 JSON 聚合测试覆盖 merge/重用、类型共享转换、distinct 和错误路径,每项三轮。此为算子状态落盘协议测试,不外推为生产大数据性能通过。回归与 CI
qa-acceptance-main中版本、正式结果、原生测试和 SDK 日志。本轮整体正式 MOTR 63/63(21 个用例各三轮)、0 失败;63 次不全属于本 Issue。待解决点
本 Issue 上述原始问题与相关边界没有未通过项。该结论不扩展为其他 Issue、大数据性能或未执行的生产拓扑验收。MOTR 回归已经提交,按用户允许先验收关闭、随后合入 PR 的流程处理。
最终结论:测试通过。原始复现、上述扩展、对应 MOTR 回归及 Linux CI 均已完成;本 Issue 验收范围内未通过项:无。按授权关闭 #28890。