Repository navigation
Description
Description
JSON_OBJECTAGG does not use the typed temporal conversion used by the other JSON constructors. A YEAR value is rejected, and valid TIME/DATETIME values lose their fractional seconds. The altered values are returned and persisted through normal aggregation, window aggregation, CTAS, views, prepared statements, parallel execution, and aggregate spill.
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_objectagg_temporal_repro;
USE json_objectagg_temporal_repro;
CREATE TABLE t (
k VARCHAR(16),
y YEAR,
tm0 TIME,
tm6 TIME(6),
dt0 DATETIME,
dt6 DATETIME(6)
);
INSERT INTO t VALUES
('a', 2024, '12:34:56', '12:34:56.123456',
'2024-02-29 12:34:56', '2024-02-29 12:34:56.123456'),
('b', NULL, NULL, NULL, NULL, NULL);
SELECT JSON_OBJECTAGG(k, y) FROM t;
SELECT JSON_OBJECTAGG(k, tm0), JSON_OBJECTAGG(k, tm6),
JSON_OBJECTAGG(k, dt0), JSON_OBJECTAGG(k, dt6)
FROM t;MatrixOne result
The YEAR query is rejected:
ERROR 20301 (HY000): invalid input: unsupported type for json aggregate: YEAR
The remaining query returns:
{"a":"12:34:56","b":null}
{"a":"12:34:56","b":null}
{"a":"2024-02-29 12:34:56","b":null}
{"a":"2024-02-29 12:34:56","b":null}
Both declared scale 0 and scale 6 collapse to the same JSON strings. For scale 6 this silently removes .123456.
MySQL 8.0.45 result
{"a":2024,"b":null}
{"a":"12:34:56.000000","b":null}
{"a":"12:34:56.123456","b":null}
{"a":"2024-02-29 12:34:56.000000","b":null}
{"a":"2024-02-29 12:34:56.123456","b":null}
JSON_OBJECT and the current JSON_ARRAYAGG implementation in MatrixOne also retain the scale-6 value, so the loss is specific to the object aggregate value-conversion path.
Scope and repeatability
- The scalar aggregate, ordered window aggregate, CTAS result, view result, and prepared execution reproduce the same conversion on every run.
- A 160,000-row / 40,000-group test returns all 40,000 complete JSON objects, but zero objects retain the TIME(6) or DATETIME(6) expected value.
- That scale test reproduces 3/3 with
max_dop=1andmax_dop=8, both resident and withagg_spill_mem=65536; the low-threshold runs enter multi-level aggregate spill and complete with the same altered values. - NULL values remain JSON null and object membership is complete; the problem is the non-NULL temporal atom conversion.
Code analysis
pkg/sql/plan/function/list_agg.go admits every non-binary value type for JSON_OBJECTAGG. In pkg/sql/colexec/aggexec/jsonagg2.go, both the normal jsonObjectAggExec.BatchFill path and the allocation-accounted spill path call the generic buildValueByteJson / appendJSONAggregateValue functions directly. Those functions do not handle YEAR, and they format TIME/DATETIME with String(), which drops declared fractional precision.
The recently merged JSON_ARRAYAGG fix routes TIME, DATETIME, and YEAR through jsonvalue.FromVector; the corresponding object-aggregate route is still absent.
Expected behavior
JSON_OBJECTAGG should accept YEAR values and preserve temporal scale and fractional content consistently with MatrixOne's other JSON constructors and MySQL 8. The corrected conversion must be shared by normal, accounted/spill, merge, window, CTAS/view, and prepared execution paths.
Activity
jiangxinmeng1 commentedon Oct 21, 2026
fixed by #28932
Ariznawlll commentedon Oct 21, 2026
测试版本
main63a964a82fbaae4759cfabb45655e0185bc0979c0c3f7e035d90fbcf205b3164c560eda2df38335e;GitHub compare 确认它是上述 main 的祖先(ahead 399、behind 0)。127.0.0.1:46001;未使用共享 TKE。原问题验证
通过真实 MySQL 协议执行
JSON_OBJECTAGG,分别输入YEAR、TIME(0)、TIME(6)、DATETIME(0)、DATETIME(6)和 SQL NULL。独立预期与实际值均一致,连续 3/3:YEAR为{"a":2024,"b":null};TIME(0)为12:34:56.000000,TIME(6)为12:34:56.123456;DATETIME(0)为2024-02-29 12:34:56.000000,DATETIME(6)为2024-02-29 12:34:56.123456。未出现原报告的 YEAR 拒绝或微秒截断。按报告规模创建 160,000 行、40,000 个分组,每组 4 个键(包含 JSON null)。
max_dop=1/8×agg_spill_mem=0/65536四组设置分别运行 3 次,共 12/12;每次分组数、对象键数、YEAR、NULL、TIME(6)、DATETIME(6) 的校验计数均为40000。低阈值的EXPLAIN ANALYZE实际显示聚合SpillRows=471360、SpillSize=52.81 MiB,不是仅设置阈值而未触发 spill。Happy Path 覆盖
JSON_OBJECT和JSON_ARRAYAGG对照值正确;JSON_OBJECTAGG的 CTAS、view、SQL PREPARE/EXECUTE、窗口聚合路径均保留 YEAR 与 TIME/DATETIME 微秒,3/3。Unhappy Path 覆盖
JSON_OBJECTAGG(NULL,tm6)连续 3/3 返回ERROR 20301: invalid input: json_objectagg key cannot be NULL;随后原表仍为 2 行、合法聚合仍返回12:34:56.123456,确认错误后会话和数据未受损。白盒验证
本轮未重复运行修复 PR 的 Go UT;验收以隔离部署上的公开 SQL 路径、原规模分组以及实际 spill 为准。修复 PR 自述的 Go 测试不计入本轮独立测试次数。
回归测试
t/issue_28889_json_objectagg_temporal.test与r/issue_28889_json_objectagg_temporal.result,PR headd8173ae5。预期值由 SQL/JSON 语义独立确定,逐项核对 golden 全为预期的1、非法键为 20301。--repeat 3:3/3、57/57 语句通过;完整 suite 与集成 CI 本轮未执行,PR 尚未合入,后续继续跟踪。该轻量回归不替代上述已独立完成的 160k/40k spill 验收。测试证据
/tmp/mo-28889-qa-jUbdgJ/verify_core.py(3/3 原路径、对照、错误恢复)、/tmp/mo-28889-qa-jUbdgJ/verify_scale.py(12/12 规模组合及EXPLAIN ANALYZE的 52.81 MiB spill)、/tmp/mo-28889-qa-jUbdgJ/motr-reports/(MOTR 3/3)。测试结论
测试通过。