Skip to content

[Bug]: JSON aggregates serialize TIMESTAMP in UTC instead of the session time zone #28890

Description

@Ariznawlll

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_ARRAYAGG and JSON_OBJECTAGG are 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

  1. added this to the MO-202609 milestone on Sep 15, 2026
  2. added theissue type on Sep 15, 2026
  3. added a commit that references this issue on Oct 8, 2026
    a85aeb5
  4. Ariznawlll commented on Nov 29, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。JSON_ARRAYAGG/JSON_OBJECTAGG 现在按执行时会话时区输出 TIMESTAMP,不再固定使用 UTC 或追加 UTC 后缀。

    关键证据

    版本与环境

    • 此项按 main 验收。本地隔离双 CN 实测 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 通过。
    • 原生源码测试使用该版本;[Bug]: PREPARE'd LOAD DATA re-bind drops its column list and SET/NULLIF — rows load into the wrong columns #31315 的测试 overlay 只增加测试与适配 BuildPlan 调用签名,没有修改产品实现。SQL 与协议测试连接实际启动的服务。

    步骤、断言与实际结果

    原值 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 恢复原值。

    • 同一连接依次切换 +00:00、+08:00、-05:30、+00:00;普通聚合、VIEW、预先 PREPARE 的 EXECUTE 均按当前时区变化。以 Python datetime 独立计算预期,不复制服务端输出作为 golden。
    • JSON 数组按元素多重集合校验,JSON 对象逐键精确匹配;微秒、JSON null、空集、窗口前缀均检查。
    • +08:00 下 CTAS 固化 JSON,切为 -05:30 读回仍为创建时文本;回滚 UPDATE 后聚合与原表保持正确。
    • 原生 TestAccountedJSONAggregatesLifecycleAndSpill 包含 array/object TIMESTAMP 时区边界和真实 spill state 编解码;其余 JSON 聚合测试覆盖 merge/重用、类型共享转换、distinct 和错误路径,每项三轮。此为算子状态落盘协议测试,不外推为生产大数据性能通过。

    回归与 CI

    • 回归追加现有 MOTR main PR #374,未向 MatrixOne 主库提测试 PR。
    • 本项固定回归文件,本地三轮通过,Linux 正式 MOTR 本项 3/3。
    • Linux CI 46298275529 SUCCESS;已回读 qa-acceptance-main 中版本、正式结果、原生测试和 SDK 日志。本轮整体正式 MOTR 63/63(21 个用例各三轮)、0 失败;63 次不全属于本 Issue。
    • 同轮原生日志有 398 个顶层 PASS,没有顶层 FAIL/SKIP 或 DATA RACE;其中 saved-result projection 为普通20次、race3次。真实 SDK Arrow 48项通过,真实二进制 prepared 探针三轮、共24次执行通过。每项证据归属以上具体步骤,不将组合 CI 的总数重复算作本 Issue 的独立测试数量。
    • 汇总 PR 尚待合入;合入默认分支后相关每日调度才会生效,不声称尚未合入的 schedule 已在每天执行。

    待解决点

    本 Issue 上述原始问题与相关边界没有未通过项。该结论不扩展为其他 Issue、大数据性能或未执行的生产拓扑验收。MOTR 回归已经提交,按用户允许先验收关闭、随后合入 PR 的流程处理。

    最终结论:测试通过。原始复现、上述扩展、对应 MOTR 回归及 Linux CI 均已完成;本 Issue 验收范围内未通过项:无。按授权关闭 #28890。

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

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions