Skip to content

[Compatibility]: JSON constructors serialize GEOMETRY as raw WKB strings instead of GeoJSON objects #28060

Closed

Description

@Ariznawlll

Description

JSON_OBJECT, JSON_ARRAY, and JSON_SET convert a MatrixOne GEOMETRY value into a JSON string containing its raw WKB bytes. The same geometry is correctly converted to a GeoJSON object by CAST(geometry AS JSON), and MySQL 8 JSON constructors also produce a GeoJSON object. The constructor result is therefore not a usable JSON representation of the geometry.

Environment

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

Steps to reproduce

CREATE TABLE t (id INT PRIMARY KEY, g GEOMETRY);
INSERT INTO t VALUES (1, ST_GeomFromText('POINT(1 2)'));

SELECT
  JSON_TYPE(JSON_EXTRACT(JSON_OBJECT('g', g), '$.g')),
  JSON_TYPE(JSON_EXTRACT(JSON_ARRAY(g), '$[0]')),
  JSON_TYPE(JSON_EXTRACT(JSON_SET('{}', '$.g', g), '$.g')),
  JSON_UNQUOTE(JSON_EXTRACT(CAST(g AS JSON), '$.type'))
FROM t;

Actual behavior

MatrixOne returns:

STRING | STRING | STRING | Point

The members constructed by JSON_OBJECT/JSON_ARRAY/JSON_SET contain raw WKB bytes. CAST(g AS JSON) in the same row returns a GeoJSON object with type Point.

MySQL 8 returns a nested GeoJSON object through JSON_OBJECT, for example:

{"g": {"type": "Point", "coordinates": [1.0, 2.0]}}

Expected behavior

JSON constructors should use the same GeoJSON conversion as CAST(geometry AS JSON), yielding a JSON object rather than a WKB string.

Stability and controls

  • Reproducer: 3/3 on MatrixOne main for JSON_OBJECT, JSON_ARRAY, and JSON_SET.
  • JSON_VALID reports the constructor document as valid because the WKB is stored as a JSON string; this does not make the representation semantically correct.
  • Passing control: explicit CAST(g AS JSON) returns an object whose type is Point.
  • MySQL 8 control: 3/3 JSON constructor results are GeoJSON objects for the same POINT(1 2) input.

Code analysis

pkg/sql/plan/function/func_builtin_json.go handles types.T_geometry by returning string(v.GetBytesAt(row)) to JSON creation. The explicit cast implementation instead invokes the geometry-to-GeoJSON conversion path. Reusing that conversion for constructors would avoid the raw WKB string.

Regression coverage

After a fix, add deterministic constructor coverage for POINT through JSON_OBJECT, JSON_ARRAY, and JSON_SET, alongside a CAST(geometry AS JSON) equivalence check.

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. changed the title [-][Bug]: JSON constructors serialize GEOMETRY as raw WKB strings instead of GeoJSON objects[/-] [+][Compatibility]: JSON constructors serialize GEOMETRY as raw WKB strings instead of GeoJSON objects[/+] on Sep 3, 2026
  5. added
    severity/s1
    and removed on Sep 8, 2026
  6. 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 对 GEOMETRY 的 WKB-to-GeoJSON 转换,非法 WKB 仍必须报错;同时覆盖列值、NULL、预编译和重绑定路径。

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

    请在合并版本连续复验合法/非法 WKB、不同 geometry subtype、常量与列值、单 CN 与多 CN、重启/读回以及生成列/索引消费。PASS 标准是 GeoJSON 结构和错误语义与 MySQL 8 一致;FAIL 时请保留 SQL、main SHA、重复轮次和实际/期望结果。

  7. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

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

  8. VioletQwQ-0 commented on Sep 8, 2026

    @VioletQwQ-0
    Collaborator

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

  9. 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.

  10. Ariznawlll commented on Sep 9, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

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

    原问题验证

    验证空间 Point 在 JSON constructor 中生成正确 GeoJSON object,并在不同容器内保持一致。

    Happy Path 覆盖

    • Point 写入 JSON object、array、set 均产生预期 GeoJSON 类型和坐标;
    • 空间值直接 cast/control 查询也正确,连续 3 轮通过。

    Unhappy Path 覆盖

    以 object、array、set 三条序列化入口与直接 cast 控制路径交叉验证,确认空间对象不会被降级为普通字符串或在嵌套容器中变形。

    白盒验证

    不适用:以 GeoJSON 外部输出和容器内容验收。

    回归测试

    • 已加入 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 条语句成功。

    测试证据

    三种 JSON 容器和直接空间控制路径均重复 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