Skip to content

[Compatibility]: JSON_OBJECTAGG rejects numeric key expressions accepted by MySQL #28032

Closed

Description

@Ariznawlll

Description

JSON_OBJECTAGG rejects an integer key expression in MatrixOne, although MySQL accepts an expression as the object key. The same rejection occurs when the aggregate is used as a window function.

Environment

  • Branch: main
  • Commit: 17c161a31b47a22e71ca222839143f66717ac365
  • Deployment: local single-node MatrixOne
  • Test date: 2026-09-03

Steps to reproduce

-- scalar aggregate
SELECT JSON_OBJECTAGG(CAST(1 AS SIGNED), 'v');\n\n-- window aggregate\nSELECT JSON_OBJECTAGG(CAST(1 AS SIGNED), 'v') OVER ();\n```\n\n## Actual behavior\n\nBoth statements are rejected with an invalid-argument error for `JSON_OBJECTAGG`; the integer key is not accepted.\n\n## Expected behavior\n\nMySQL documents `JSON_OBJECTAGG(key, value)` with `key` and `value` as expressions. A non-NULL integer key expression should be accepted and converted to the JSON object member name, including with `OVER (...)`.\n\n## Stability and controls\n\n- Reproducer: 3/3 on the stated commit for both scalar and window forms.\n- Control: `JSON_OBJECTAGG(CAST(1 AS CHAR), 'v')`, including `OVER ()`, succeeds.\n- Scope: the failure is key-type handling in `JSON_OBJECTAGG`, not absence of window-aggregate support.\n\n## Evidence\n\nMySQL reference: https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_json-objectagg\n\n## Regression coverage\n\nAfter fixing, add scalar and window coverage for numeric, character, expression, and NULL key cases.

Activity

  1. added
    kind/bug
    on Sep 3, 2026
  2. added this to the MO-202609 milestone on Sep 3, 2026
  3. added theissue type on Sep 3, 2026
  4. Ariznawlll commented on Sep 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充范围:数值 key 限制同样影响窗口聚合。

    SELECT id, JSON_OBJECTAGG(id, v) OVER (
      PARTITION BY g ORDER BY id
      ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
    )
    FROM t;

    MySQL 将 INT key 转为 JSON 对象的字符串 key,并返回逐行累计对象;MO 在聚合构造阶段报 invalid argument aggregate function json_objectagg, bad value [INT JSON]。将 key 显式转换为 CHAR 后,MO 与 MySQL 的窗口帧结果一致。该现象连续 3 次一致。

  5. added
    kind/compatibility
    severity/s1
    and removed on Sep 4, 2026
  6. VioletQwQ-0 commented on Sep 4, 2026

    @VioletQwQ-0
    Collaborator

    Triage result: promote this issue to active severity/s1.

    The compatibility defect is confirmed. On exact upstream/main 494e6a7723242947c73442528e5fbabe62144ec3, JSON_OBJECTAGG still rejects conventional numeric key types during function overload resolution. MySQL accepts key expressions and converts a non-NULL numeric value to a JSON object member name. Scalar, grouped, and window forms share the same admission path.

    Implementation scope:

    • Accept signed and unsigned integers, FLOAT, and DECIMAL keys.
    • Insert an implicit VARCHAR cast during binding, so key formatting matches the existing explicit string-cast behavior.
    • Preserve existing character and binary-string key handling.
    • Preserve the NULL key error and last-duplicate-key-wins behavior.
    • Keep the aggregate executor's string-key invariant; no aggregate state, spill/merge, wire, or storage protocol changes are required.
    • BIT, YEAR, temporal, BOOL, ENUM, JSON, UUID, and broader binary/UTF-8 parity remain outside this issue.

    Delivery order:
    #28092 → #28093 → #28094 → a separate Draft PR for #28032.

    Validation will include resolver unit tests, scalar/grouped/window BVT, prepared explicit numeric casts, duplicate numeric keys, NULL keys, exact MySQL 8 comparison, and single-CN/multi-CN QA. The PR will use issue #28032; this issue will remain open until tester evidence reaches a terminal PASS.

  7. VioletQwQ-0 commented on Sep 16, 2026

    @VioletQwQ-0
    Collaborator

    @slyunnn 请验收本 issue,现正式转测,保持 OPEN 等待 QA 结论。按 tester 路由规则,当前标签含 kind/compatibility,且本 issue / merged PR 明确修复用户可见的 MySQL 数值 key 兼容性缺陷,测试负责人更正为 slyunnn。

    修复 PR:#28331
    PR head:4584adff21f4dc6741bb397fd893e0a4de5a4894
    main 合入 commit:ceaf9c6f88ab184d4e1684d413bfe40ae4b56a44

    开发验证:该 head 的 CI Required、Compose/Proxy BVT 均成功,合入后的 TKE BVT 成功。CI:https://github.com/matrixorigin/matrixone/actions/runs/34928251746 。依赖 #28092、#28093、#28094 均已合入。PR 正文旧 head 的本地环境阻塞/pending 快照不代表最新 CI 结果;正式 MySQL 对照和部署 QA 仍待完成。

    请在包含上述合入 commit 的版本,与 MySQL 8 对照验证 JSON_OBJECTAGG 的整数/无符号数/FLOAT/DOUBLE/DECIMAL key:scalar、GROUP BY、window/OVER(含有序 ROWS 帧)、ORDER BY/LIMIT、prepared 和重复执行,并验证与显式 CAST AS CHAR 的一致性。覆盖 NULL key 报错、NULL value、空输入、确定顺序下重复 key、保留的字符串/二进制边界,以及 BIT/BOOL/ENUM/时间/JSON/UUID 等不支持 key 的拒绝行为。单 CN/多 CN 验证聚合 partial merge、spill 和错误后复用;不以无序聚合的输入顺序推定重复 key 胜出值。

    回归入口:test/distributed/cases/function/func_json_agg.test、test/distributed/cases/window/mysql_compat_window_json_arrayagg.sql。
    请记录实际 build/commit、环境拓扑、MySQL 版本、各场景 PASS/FAIL;失败附最小 SQL 和实际/期望结果。未运行场景明确标为 NOT_RUN,不作为通过。

  8. slyunnn commented on Sep 16, 2026

    @slyunnn

    Regression and extended verification for #28032 (2026-09-16)

    Verification Environment

    • MatrixOne source and running binary: 8a4c84f4516d5098de9eef50b8afecc7524f37a2 — fix compatibility for concat, prepared elt, and string numeric results (#28915); the binary reported commit 8a4c84f451 at startup.
    • Topology: 1 Log service / 1 TN / 2 CN / 1 Proxy.
    • MySQL protocol endpoints: Proxy 127.0.0.1:6001, CN1 127.0.0.1:16001, and CN2 127.0.0.1:16002. All three were connected successfully, and the original regression SQL plus the extension matrix were executed through each endpoint; the BVT replay used the local MySQL-protocol service path.
    • Compatibility control: a temporary MySQL 8.3.0 instance using the MySQL TCP protocol.
    • Related fix: ceaf9c6f88ab184d4e1684d413bfe40ae4b56a44, fix(json): accept numeric keys in json_objectagg. The fix resolves numeric keys to the existing VARCHAR key path while retaining the established key-type boundaries.

    What Was Covered

    • OK — Original scalar reproduction: SELECT JSON_OBJECTAGG(CAST(1 AS SIGNED), 'v') returned key "1" with value "v" through Proxy, CN1, and CN2.
    • OK — Signed/unsigned integer, FLOAT, DOUBLE, DECIMAL, and arithmetic-expression keys produced the same JSON value as explicit CAST(... AS CHAR).
    • OK — GROUP BY with ORDER BY/LIMIT and JSON_OBJECTAGG(...) OVER (PARTITION BY ... ORDER BY ... ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) returned the expected aggregate and running-window values on all three endpoints.
    • OK — Server-side PREPARE/EXECUTE with a numeric parameter succeeded repeatedly and returned the expected key for the matching bound value.
    • OK — Empty input returned NULL; a NULL value was retained as JSON null; ordered duplicate numeric key input retained the last value; CHAR and BINARY key inputs remained usable.
    • OK — NULL key was rejected with 20301; BOOL, DATE, and JSON key inputs were rejected with 20203; a subsequent valid query succeeded in the same session.
    • OK — MySQL 8.3.0 control produced the same results for numeric key coercion, grouping, ordered windows, prepared execution, empty input, duplicate keys, and NULL-key error recovery.
    • Not covered — Forced spill, physical partial-merge stress, and large-volume execution. The defect is a bind-time type-resolution path; it does not depend on row count, block/batch boundaries, memory/spill, network transfer, or resource scale.

    Findings

    The reported compatibility defect is fixed on the verified main runtime. Numeric JSON_OBJECTAGG keys now follow the intended implicit VARCHAR conversion, matching explicit CHAR conversion and the MySQL control for the covered types and execution forms. Existing restrictions for NULL, BOOL, temporal, and JSON keys remain intentional and were not broadened by this fix.

    Large-data regression is not required: increasing cardinality would not exercise a different bind/type-resolution path and would add unrelated CI cost. Multi-CN reachability and actual SQL execution were verified, but no artificial spill or partial-merge workload was added for this binder-only change.

    MOTR / BVT Coverage

    • No MOTR change was needed: the canonical BVT coverage already exists on main.
    • test/distributed/cases/function/func_json_agg.test passed twice: 96/96 each run. It covers scalar numeric families, explicit-cast equivalence, expressions, NULL value/key behavior, GROUP BY/LIMIT, duplicate keys, empty input, and prepared statements.
    • test/distributed/cases/window/mysql_compat_window_json_arrayagg.sql passed: 17/17, including numeric JSON_OBJECTAGG window keys and ordered-frame behavior.
    • Focused CGo unit tests passed: TestJSONObjectAggNumericKeyResolution and TestJSONObjectAggKeyTypeBoundaries, covering supported numeric types and preserved accepted/rejected type boundaries.

    Final Conclusion

    Fixed. The original and expanded SQL contracts passed on the latest verified main binary through Proxy, CN1, and CN2, with MySQL 8.3.0 compatibility confirmation. No new MOTR regression case is required because the existing focused unit tests and canonical BVT cases already cover the repaired behavior. Large-data regression is not required for this bind-time compatibility fix.

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

Metadata

Metadata

Assignees

Labels

kind/bugkind/compatibilityphase/testingseverity/s1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions