Skip to content

[Bug]: JSON_QUOTE returns JSON type instead of a string #28045

Closed

Description

@Ariznawlll

Description

JSON_QUOTE() returns the SQL JSON type in MatrixOne, but MySQL returns a utf8mb4 string. The value displays as JSON text, yet standard string functions cannot consume it without an explicit cast.

Environment

  • Branch: main
  • Commit: 17c161a31b47a22e71ca222839143f66717ac365
  • Deployment: local single-CN test service
  • Test date: 2026-09-03
  • MySQL control: isolated MySQL 8.0.45

Steps to reproduce

SELECT JSON_QUOTE('abc');
SELECT HEX(JSON_QUOTE('abc'));
SELECT CHAR_LENGTH(JSON_QUOTE('abc'));
SELECT CONCAT(JSON_QUOTE('abc'), 'x');

Actual behavior

MatrixOne displays JSON_QUOTE('abc') as "abc", but each string composition returns an overload/type error:

HEX:         invalid argument function hex, bad value [JSON]
CHAR_LENGTH: invalid argument function char_length, bad value [JSON]
CONCAT:      invalid argument function concat, bad value [JSON VARCHAR]

This reproduces 3/3 times.

Expected behavior

MySQL 8.0.45 returns a string value, so all three compositions are valid:

JSON_QUOTE('abc')        -> "abc"
HEX(JSON_QUOTE('abc'))   -> 2261626322
CHAR_LENGTH(JSON_QUOTE('abc')) -> 5
CONCAT(JSON_QUOTE('abc'), 'x') -> "abc"x

Reference: https://dev.mysql.com/doc/refman/8.0/en/json-creation-functions.html#function_json-quote

Stability and controls

  • Reproducer: 3/3.
  • MySQL 8.0.45 control returns the values above.
  • MatrixOne control: explicit CAST(JSON_QUOTE('abc') AS VARCHAR) is accepted, confirming the generated text itself is valid; the defect is the declared return type.
  • No DDL or DML is involved.

Code analysis

pkg/sql/plan/function/list_builtIn.go registers JSON_QUOTE with retType types.T_json. The implementation in pkg/sql/plan/function/func_unary.go:JsonQuote generates serialized JSON text, but MySQL exposes this function as a string result. Registering the result as JSON blocks normal string-function composition.

Regression coverage

After the fix, add return-type/composition coverage for JSON_QUOTE() with HEX, CHAR_LENGTH, and CONCAT, in addition to a direct value assertion.

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. added
    severity/s1
    and removed on Sep 4, 2026
  5. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

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

    关联合并:PR #28091(merge commit 3d46ea9);当前 main=1cfec4c80134adc5640a3bbf1aef7aaa87a45282。

    本次范围:JSON_QUOTE 返回 utf8mb4_bin 文本而非 JSON 类型,保留完整 prepared value,不引入窄化执行 cast;同时复验 ENUM/SET、CTAS 及持久化 JSON 消费者。

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

    请在合并版本连续复验返回类型/metadata、prepared execute 与 rebinding、字符集和 escaping、CTAS、生成列/索引/持久化消费、单 CN 与多 CN、重启/读回。PASS 标准是 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 #28091 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。

    原问题验证

    验证 JSON_QUOTE 的返回值类型与内容可正确保留 JSON 字符串的引号和转义。

    Happy Path 覆盖

    • 直接输出、HEX()、CHAR_LENGTH()、CONCAT() 均验证 JSON_QUOTE('abc') 返回 \"abc\";
    • 引号、反斜杠和 Unicode 字符串均得到可用 JSON string,连续 3 轮通过。

    Unhappy Path 覆盖

    • JSON_QUOTE(NULL) 返回 NULL,不被错误序列化为字符串 null;
    • 转义输入经过 CONCAT 后仍保持正确字节和长度,无截断。

    白盒验证

    不适用:以 SQL 输出、字节表示和组合表达式验证结果类型/内容。

    回归测试

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

    测试证据

    直接、组合、转义与 NULL 场景均重复 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