Skip to content

[Compatibility]: JSON constructors serialize YEAR values as strings instead of numbers #28058

Closed

Description

@Ariznawlll

Description

MatrixOne serializes a SQL YEAR value as a JSON string, while MySQL 8 serializes it as a JSON number. This changes JSON_TYPE, containment predicates, and any generated/indexed value derived from the JSON document.

Environment

  • Branch: main
  • Commit: 95d04586eb80864499d0fde27aeb912b463ae4cd
  • Deployment: local single-CN MatrixOne

Steps to reproduce

CREATE TABLE t (id INT PRIMARY KEY, y YEAR);
INSERT INTO t VALUES (1, 2024);

SELECT
  JSON_TYPE(JSON_EXTRACT(JSON_ARRAY(y), '$[0]')),
  JSON_TYPE(JSON_EXTRACT(JSON_SET('{}', '$.year', y), '$.year')),
  JSON_CONTAINS(JSON_OBJECT('year', y), '2024', '$.year'),
  JSON_CONTAINS(JSON_OBJECT('year', y), '"2024"', '$.year')
FROM t;

Actual behavior

MatrixOne returns:

STRING | STRING | 0 | 1

The JSON value is "2024".

MySQL 8 returns:

UNSIGNED INTEGER | UNSIGNED INTEGER | 1 | 0

The JSON value is the number 2024.

Expected behavior

For MySQL compatibility, JSON constructors should represent SQL YEAR values as JSON numbers.

Stability and controls

  • Reproducer: 3/3 on MatrixOne main through JSON_ARRAY and JSON_SET.
  • JSON_OBJECT produces the same string representation.
  • MySQL 8 control consistently produces a numeric JSON value for the same row.
  • ENUM control: both systems serialize ENUM('medium') as the JSON string "medium"; the difference is specific to YEAR.

Code analysis

pkg/sql/plan/function/func_builtin_json.go handles types.T_year by formatting the value with strconv.FormatInt and returning a Go string. JSON creation therefore emits a JSON string rather than a numeric scalar.

Regression coverage

After a fix, add deterministic YEAR coverage through JSON_OBJECT, JSON_ARRAY, and JSON_SET, including JSON_TYPE and numeric/string JSON_CONTAINS controls.

Activity

  1. added this to the MO-202609 milestone on Sep 3, 2026
  2. added
    kind/bug
    on Sep 3, 2026
  3. added theissue type on Sep 3, 2026
  4. added
    severity/s1
    and removed on Sep 8, 2026
  5. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

    【QA 交接|PR #28093 已合并】

    关联合并:PR #28093(merge commit 8836fb4);当前 main=1cfec4c80134adc5640a3bbf1aef7aaa87a45282。

    本次范围:JSON_OBJECT、JSON_ARRAY、JSON_SET 及聚合入口对 YEAR 的兼容语义,YEAR 应作为 numeric atom 暴露为 JSON INTEGER,而不是字符串;同时覆盖 NULL、预编译和重绑定路径。

    合并后证据:PR required checks 无失败;本地 exact-main CGo 自测因缺少 cgo/libmo.dylib 阻塞,mo-tester 未安装,未宣称本地 PASS。

    请在合并版本连续复验构造函数和聚合函数、常量与列值、单 CN 与多 CN、重启/读回以及生成列/索引消费。PASS 标准是 JSON 类型和值与 MySQL 8 一致;FAIL 时请保留 SQL、main SHA、重复轮次和实际/期望结果。

  6. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

    补充 pin:远端 main 已推进到 9f87b62。请以该当前 main 复验;此前列出的合并提交、测试范围和 PASS/FAIL 标准保持不变。该更新不代表 QA PASS。

  7. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

    再次补充 pin:远端 main 已推进到 9cedf6e。请以该当前 main 复验;此前列出的合并提交、测试范围和 PASS/FAIL 标准保持不变。该更新不代表 QA PASS。

  8. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

    Automation checkpoint: merged PR #28093 is being validated against current upstream/main 6d44c50. This issue remains open in phase/testing; no terminal tester PASS has been recorded in the current handoff. Please report complete version, environment, scoped scenario results, and terminal PASS/FAIL evidence before any closure decision.

  9. Ariznawlll commented on Sep 9, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:a9d3b8b857c44f1249e682c91d4d62a914eb7d20
    • 环境:本地单机 MatrixOne,2026-09-09。

    原问题验证

    验证 YEAR 进入 JSON constructor 后是数值而非字符串,并可被数值 containment 正确匹配。

    Happy Path 覆盖

    • YEAR 在 JSON object、array、set 中均编码为 INTEGER;
    • 数值 containment 命中,连续 3 轮通过。

    Unhappy Path 覆盖

    • 等价字符串 containment 不命中,确认数值没有退化为字符串;
    • 三种 JSON 容器均保持同一数值语义。

    白盒验证

    不适用:以 JSON 类型及 containment 可见结果验证。

    回归测试

    • 已加入 MOTR PR #152:suites/14_issue_regression/t/issue_28056_28057_28058_28060_json_constructor_types.test。
    • --record --repeat 3 和非 record --repeat 3 均通过;PR 共 21/21 用例、321/321 条语句成功。

    测试证据

    object/array/set、数值命中和字符串不命中均重复 3 次。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugphase/testingseverity/s1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions