Repository navigation
add json_contains_path - #25672
Merged
XuPeng-SH merged 4 commits intoJul 13, 2026
Merged
add json_contains_path#25672
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
approved these changes
Jul 13, 2026
XuPeng-SH
left a comment
Contributor
There was a problem hiding this comment.
LGTM after reviewing this from the function semantics, bytejson path-existence, and unhappy-path angles.
- correctness:
json_contains_pathnow follows the intended one/all and NULL semantics, andPathExistschecks “does the path select any JSON value?” rather than reusing extract-style result shaping - behavior fidelity: the implementation preserves the important edge cases called out in the PR description — JSON literal
nullcounts as existing, scalar$[0]autowrap works, and one/all short-circuiting prevents later NULL/invalid paths from overriding an already-settled result - unhappy path coverage: the new UT/BVT coverage exercises invalid mode/path/document inputs, recursive descent/wildcards, short-circuit order, dynamic mode/path columns, and the bytejson existence helper directly
I did not find a remaining correctness, leak, or hang issue in the latest diff, so approving.
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#24738 ## What this PR does / why we need it: • json_contains_path 的实现分成三层: 1. 函数注册和类型检查 在 matrixone/pkg/sql/plan/function/list_builtIn.go:1379 注册 json_contains_path,返回类型是 int64。 在 matrixone/pkg/sql/plan/function/func_builtin_json.go:139 做参数检查:至少 3 个参数,doc 可以是 json 或 MySQL string,其他参数要求字符串或可隐式 cast 到 varchar。 2. 执行逻辑 主执行函数在 matrixone/pkg/sql/plan/function/func_builtin_json.go:322。执行顺序是: - 先解析 doc,doc 为 SQL NULL 直接返回 NULL; - 再解析 one/all,大小写不敏感,非法值报错; - 再按参数顺序逐个解析 path; - one 模式遇到第一个存在 path 就返回 1; - all 模式遇到第一个不存在 path 就返回 0; - path 为 SQL NULL 时返回 NULL; - 短路后不会继续解析后面的 path,所以后面的 NULL 或非法 path 不会覆盖已确定结果。 3. 路径存在性判断 JSON path 是否存在由 matrixone/pkg/container/bytejson/bytejson.go:449 的 ByteJson.PathExists 负责。这里和 json_extract 不同,只关心 path 是否选中至少一个 JSON 值;JSON literal null 也算 path 存在。还补了 scalar array autowrap 语义,比如 '1' 的 $[0] 算存在。 另外实现里给 const mode/path 做了缓存:matrixone/pkg/sql/plan/function/func_builtin_json.go:422,避免每行重复解析常量 one/all 和 JSON path。BVT 覆盖在 func_json_contains_path.test/result,UT 覆盖在 func_json_valid_test.go。 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#24738 ## What this PR does / why we need it: • json_contains_path 的实现分成三层: 1. 函数注册和类型检查 在 matrixone/pkg/sql/plan/function/list_builtIn.go:1379 注册 json_contains_path,返回类型是 int64。 在 matrixone/pkg/sql/plan/function/func_builtin_json.go:139 做参数检查:至少 3 个参数,doc 可以是 json 或 MySQL string,其他参数要求字符串或可隐式 cast 到 varchar。 2. 执行逻辑 主执行函数在 matrixone/pkg/sql/plan/function/func_builtin_json.go:322。执行顺序是: - 先解析 doc,doc 为 SQL NULL 直接返回 NULL; - 再解析 one/all,大小写不敏感,非法值报错; - 再按参数顺序逐个解析 path; - one 模式遇到第一个存在 path 就返回 1; - all 模式遇到第一个不存在 path 就返回 0; - path 为 SQL NULL 时返回 NULL; - 短路后不会继续解析后面的 path,所以后面的 NULL 或非法 path 不会覆盖已确定结果。 3. 路径存在性判断 JSON path 是否存在由 matrixone/pkg/container/bytejson/bytejson.go:449 的 ByteJson.PathExists 负责。这里和 json_extract 不同,只关心 path 是否选中至少一个 JSON 值;JSON literal null 也算 path 存在。还补了 scalar array autowrap 语义,比如 '1' 的 $[0] 算存在。 另外实现里给 const mode/path 做了缓存:matrixone/pkg/sql/plan/function/func_builtin_json.go:422,避免每行重复解析常量 one/all 和 JSON path。BVT 覆盖在 func_json_contains_path.test/result,UT 覆盖在 func_json_valid_test.go。 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#24738 ## What this PR does / why we need it: • json_contains_path 的实现分成三层: 1. 函数注册和类型检查 在 matrixone/pkg/sql/plan/function/list_builtIn.go:1379 注册 json_contains_path,返回类型是 int64。 在 matrixone/pkg/sql/plan/function/func_builtin_json.go:139 做参数检查:至少 3 个参数,doc 可以是 json 或 MySQL string,其他参数要求字符串或可隐式 cast 到 varchar。 2. 执行逻辑 主执行函数在 matrixone/pkg/sql/plan/function/func_builtin_json.go:322。执行顺序是: - 先解析 doc,doc 为 SQL NULL 直接返回 NULL; - 再解析 one/all,大小写不敏感,非法值报错; - 再按参数顺序逐个解析 path; - one 模式遇到第一个存在 path 就返回 1; - all 模式遇到第一个不存在 path 就返回 0; - path 为 SQL NULL 时返回 NULL; - 短路后不会继续解析后面的 path,所以后面的 NULL 或非法 path 不会覆盖已确定结果。 3. 路径存在性判断 JSON path 是否存在由 matrixone/pkg/container/bytejson/bytejson.go:449 的 ByteJson.PathExists 负责。这里和 json_extract 不同,只关心 path 是否选中至少一个 JSON 值;JSON literal null 也算 path 存在。还补了 scalar array autowrap 语义,比如 '1' 的 $[0] 算存在。 另外实现里给 const mode/path 做了缓存:matrixone/pkg/sql/plan/function/func_builtin_json.go:422,避免每行重复解析常量 one/all 和 JSON path。BVT 覆盖在 func_json_contains_path.test/result,UT 覆盖在 func_json_valid_test.go。 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: XuPeng-SH <[email protected]>
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #24738
What this PR does / why we need it:
• json_contains_path 的实现分成三层:
函数注册和类型检查
在 matrixone/pkg/sql/plan/function/list_builtIn.go:1379 注册 json_contains_path,返回类型是 int64。
在 matrixone/pkg/sql/plan/function/func_builtin_json.go:139 做参数检查:至少 3 个参数,doc 可以是 json 或 MySQL string,其他参数要求字符串或可隐式 cast 到 varchar。
执行逻辑
主执行函数在 matrixone/pkg/sql/plan/function/func_builtin_json.go:322。执行顺序是:
路径存在性判断
JSON path 是否存在由 matrixone/pkg/container/bytejson/bytejson.go:449 的 ByteJson.PathExists 负责。这里和 json_extract 不同,只关心 path 是否选中至少一个 JSON 值;JSON literal null 也算 path 存在。还补了 scalar array autowrap 语义,比如 '1' 的 $[0] 算存在。
另外实现里给 const mode/path 做了缓存:matrixone/pkg/sql/plan/function/func_builtin_json.go:422,避免每行重复解析常量 one/all 和 JSON path。BVT 覆盖在 func_json_contains_path.test/result,UT 覆盖在 func_json_valid_test.go。