Skip to content

add json_contains - #25478

Merged
mergify[bot] merged 12 commits into
matrixorigin:mainfrom
daviszhen:0706-fix-json-contains
Jul 9, 2026
Merged

mergify[bot] merged 12 commits into
matrixorigin:mainfrom
daviszhen:0706-fix-json-contains

Conversation

@daviszhen

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #24732

What this PR does / why we need it:

增加 json_contains函数

@daviszhen
daviszhen requested a review from a user July 6, 2026 09:05
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for two semantic blockers:

  1. pkg/sql/plan/function/func_builtin_json.go:351-365 + test/distributed/cases/function/func_json_contains.result:130-138

    • jsonScalarsComparable only treats exact same TYPE() or INTEGER/DECIMAL pairs as comparable. That excludes JSON DOUBLE, so JSON_CONTAINS(1,1.0), JSON_CONTAINS({"a":1},{"a":1.0}), and [1,2,3] vs [1.0,3.0] all return 0 and the new BVT locks that in. For MySQL-compatible JSON_CONTAINS, numeric JSON scalars need numeric equality across INT/UINT/DOUBLE/DECIMAL, not type-equality except for int/decimal.
    • Suggested fix: reuse a numeric-aware scalar comparator for all numeric JSON types instead of the current TYPE() / INTEGER-or-DECIMAL gate.
  2. pkg/sql/plan/function/func_builtin_json.go:238-245 + pkg/container/bytejson/bytejson.go:461-507

    • The path branch uses QuerySimpleExist(), and that helper returns “path not found” once it hits a scalar with an array-index leg. That drops MySQLs scalar [0] autowrap semantics for simple paths. Cases like JSON_CONTAINS(1,1,$[0]) or JSON_CONTAINS({"a":1},1,$.a[0]) should match, but this implementation would return NULL.
    • Suggested fix: either use the normal JSON path extractor for the third argument or extend QuerySimpleExist() to honor the same scalar [0] autowrap rule.

@daviszhen

Copy link
Copy Markdown
Contributor Author

I rechecked the current head and one substantive blocker remains.

The old 1 vs 1.0 incompatibility is fixed, but the new numeric path is now too permissive for mixed integer/float JSON values.

jsonContainsScalar() delegates mixed numeric equality to bytejson.CompareByteJson(), and that comparator is an ordering helper with float-oriented tolerance and float64 coercion. So distinct numeric values can now be treated as equal in JSON_CONTAINS.

Two concrete bad cases are:

  • JSON_CONTAINS('1', '1.000000009')
  • JSON_CONTAINS('9007199254740993', '9007199254740992.0')

The first can collapse because the mixed numeric comparison path treats tiny float/int diffs below its precision-loss threshold as equal. The second can collapse because converting large integers to float64 loses precision above 2^53.

That means the PR has traded the old false negatives for new false positives. For containment semantics, that is still a correctness bug. This needs an exact numeric-equality path for JSON numeric containment checks rather than reusing the general ordering comparator.

已经修改

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked the latest head after the requested fixes.

The previous semantic blockers are addressed:

  • Numeric containment no longer reuses the general ordering comparator for equality. The new path has exact checks across int/uint/float/decimal cases, and the regressions for vs , large integers above 2^53, uint64 boundaries, and decimal/float cases are covered by UT/BVT.
  • The third-argument path flow now uses a JSON_CONTAINS-specific simple-path lookup with scalar autowrap, without changing the existing QuerySimple/JSON modify behavior. Missing paths still return NULL, and wildcard/non-simple paths error as required.

I also checked the function registration/ID changes, strict/null handling, invalid JSON/path unhappy paths, typed JSON inputs, arrays/objects/scalars, and select-list skip behavior. CI is green, and I locally ran the targeted bytejson and function tests for the new code paths.

Approved.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked the latest head after the requested fixes.

The previous semantic blockers are addressed:

  • Numeric containment no longer reuses the general ordering comparator for equality. The new path has exact checks across int/uint/float/decimal cases, and the regressions for 1 vs 1.000000009, large integers above 2^53, uint64 boundaries, and decimal/float cases are covered by UT/BVT.
  • The third-argument path flow now uses a JSON_CONTAINS-specific simple-path lookup with scalar [0] autowrap, without changing the existing QuerySimple/JSON modify behavior. Missing paths still return NULL, and wildcard/non-simple paths error as required.

I also checked the function registration/ID changes, strict/null handling, invalid JSON/path unhappy paths, typed JSON inputs, arrays/objects/scalars, and select-list skip behavior. CI is green, and I locally ran the targeted bytejson and function tests for the new code paths.

Approved.

@mergify mergify Bot added the queued label Jul 9, 2026
@mergify

mergify Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-09 03:57 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-07-09 07:45 UTC · at 0e6c8778d17e042494226c659540e6026c7f19d1 · squash

This pull request spent 3 hours 48 minutes in the queue, including 2 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64

@mergify
mergify Bot merged commit 2037cc8 into matrixorigin:main Jul 9, 2026
23 of 24 checks passed

This branch was previously deployed

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

Labels

kind/bug Something isn't working kind/enhancement size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants