Skip to content

fix(json): return escaped text from JSON_QUOTE - #28091

Merged
XuPeng-SH merged 11 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issues-28044-28045-json-quote-text
Sep 8, 2026
Merged

XuPeng-SH merged 11 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issues-28044-28045-json-quote-text

Conversation

@VioletQwQ-0

@VioletQwQ-0 VioletQwQ-0 commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #28044
issue #28045

What this PR does / why we need it:

Return JSON_QUOTE as utf8mb4_bin text instead of binary JSON. Validate UTF-8 and the runtime string domain, emit JSON string escapes, preserve SQL NULL, derive the expanding result bound, and retain full prepared values without a synthetic narrowing execution cast. Existing ENUM/SET-to-JSON planner consumers explicitly cast quoted display text back to JSON.

Landing status

  • The required JSON_UNQUOTE predecessor fix(json): preserve plain text in JSON_UNQUOTE #28090 is merged as 3d2e5c336ed6b6d034908cd4d2012bc9737fe958 and is an ancestor of this exact head.
  • Main was integrated through commit 2a12a06aa1931c93c53c11d34465e832a9713cf8, resolving the latest upstream test-file conflict while retaining the JSON_QUOTE regression and upstream prepared-interval coverage. It includes merged fix(temp): keep ALTER COPY DDL in executor transaction #28356 (fdc1e0ca8f9696ada9668408e8caffc1d3b7c924) for temporary ALTER COPY transaction ownership.
  • Exact current head: 2a12a06aa1931c93c53c11d34465e832a9713cf8; this PR remains Ready and must continue through normal merge protections.
  • The prior CI run on fb6a10200e86073c5954288c74718daca7f3c2c8 reported func_json_quote.test 54/54 PASS. Its PROXY job failed only in the unrelated temporary-table ALTER path (16 failures, including allocator metadata errors), UT Coverage timed out after repeated dependency-download curl timeouts before a terminal coverage report, and Utils Coverage was downstream (PREREQUISITES_READY=false). Fresh CI for this head is pending.
  • The fresh CI run 34207581205 on the preceding exact head c8eaf2cf515d235ed1ee5da0d4b69043993bfc17 passed SCA, main UT, PROXY BVT, and standalone pessimistic BVT. UT Coverage alone failed on unrelated pkg/common/mpool/TestReallocPhysicalFailureRestoresOwnership with runner fatal error: runtime: cannot allocate memory; its diagnostics showed a 15 GiB runner with no swap. A new exact-head run is required after this upstream sync.

Validation at exact head 2a12a06aa1931c93c53c11d34465e832a9713cf8

  • Focused CGo tests for JSON_QUOTE domain rejection, UTF-8 escaping, NULL/masked rows, prepared rebinding, planner consumers, and protocol metadata on validation head 2a5842b8c69ce793aadc5fd1a0b01668e9318be5: PASS; the later c8eaf2cf result-only update and upstream-only sync did not change these production paths.
  • Full owning-package CGo tests for pkg/sql/plan/function, pkg/sql/plan, and pkg/frontend on that validation code: PASS.
  • Temporary ALTER ownership/retry/pool-reuse focused tests from fix(temp): keep ALTER COPY DDL in executor transaction #28356: PASS.
  • Targeted pkg/tests/issues CGo coverage invocation for TestIssue23861FulltextSnapshotRestore and TestIssue28317ViewSnapshotGateOrderSQL: PASS; the local report is [no statements], so it is functional targeted evidence and does not replace CI's full coverpkg mode.
  • Canonical local BVT with a fresh single-CN data directory on validation head 2a5842b8c69ce793aadc5fd1a0b01668e9318be5: func_json_quote.test 54/54 PASS; temporary_table_limitation.sql 137 total, 130 success, 7 ignored, 0 failed, 100% success. The later result-only and upstream test merge do not alter these BVT production paths.
  • Exact-head semantic preflight after the upstream sync: PASS, diff hash 87525d7984b1850cb10ce44eda17b7244e26fe9fdccf366060b137a4d773d6df.
  • git diff --check: PASS. Fresh exact-head CI is pending after this update.

BVT: extended — test/distributed/cases/function/func_json_quote.test and .result; integrated-main metadata expectations in test/distributed/cases/temporary/temporary_table_limitation.result are refreshed and the full canonical case passes.

QA required: yes — after required CI and merge protections are satisfied, verify text/protocol metadata, prepared execution, charset/escaping, CTAS and persisted consumers on the merged version. Keep the associated issues under formal QA validation.

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Sep 3, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Sep 3, 2026
@VioletQwQ-0
VioletQwQ-0 force-pushed the codex/issues-28044-28045-json-quote-text branch from e3901e2 to 260c2ab Compare September 4, 2026 03:19
@VioletQwQ-0
VioletQwQ-0 force-pushed the codex/issues-28044-28045-json-quote-text branch from 260c2ab to a5c485b Compare September 4, 2026 03:23

@aptend aptend 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.

Deep-reviewed exact head 67bb55b6e3e6f82d786c469f7dba8368aba3c3cf against merge base 3d67664696e48cec0efc84308fb7de1cfda2f7db, including the complete diff and all existing reviews, issue comments, replies, and thread state. Requesting changes because binary-domain values are accepted whenever their bytes happen to be valid UTF-8.

The declared landing dependency has also changed since the existing review: #28090 is now merged as 3d2e5c336ed6b6d034908cd4d2012bc9737fe958, but it is not an ancestor of this exact head or its recorded base. This PR explicitly requires synchronization after #28090, so the new integrated head needs re-review.

Validation: native third-party/CGo artifacts built successfully; go test -count=1 ./pkg/sql/plan/function ./pkg/sql/plan ./pkg/frontend passed; focused changed tests passed under -race; git diff --check passed. A review-only ASCII VARBINARY counterexample reproduced the blocker and was removed afterward.

Comment thread pkg/sql/plan/function/func_unary.go Resolved
@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Rechecked the exact current head bebaf521e941f0c81626dea52fea7a210ba698a2 in an isolated clean worktree. The row-aware GetIsBinaryStringAt(row) check is already present after NULL and selection-mask filtering, so ASCII binary values are rejected independently of UTF-8 validity; typed binary NULL remains NULL, and mixed/masked rows preserve row semantics.

Exact-head CGo validation:

  • TestJsonQuoteRejectsBinaryDomain: PASS (BINARY/VARBINARY/BLOB ASCII, invalid bytes, typed NULL, mixed and masked rows)
  • TestCOMStmtJsonQuoteRebindExecutesWithWireStringDomain: PASS (text -> binary -> text rebind)

The current inline P2 is addressed by this head; requesting re-review.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Exact current head: fb6a10200e86073c5954288c74718daca7f3c2c8.

The attempt-2 BVT failures in the existing func_json_quote case were caused by three control-character/prepared fixtures using CHAR(...) without an explicit charset. MatrixOne follows the existing binary-string contract: default CHAR(...) is binary, while CHAR(... USING utf8mb4) is text. The JSON_QUOTE binary-domain rejection therefore remains intentional.

This update changes the affected text fixtures to explicit utf8mb4 text and refreshes the normalized result labels. It does not weaken the runtime domain check.

Validation:

  • exact-head plan CHAR-domain contract: PASS
  • exact-head JSON_QUOTE binary-domain regression: PASS
  • exact-head CHAR binary/text unit tests: PASS
  • direct MySQL-protocol checks: PASS for control escapes, the 16384-byte prepared boundary (98306), and the 65535-byte TEXT path (393212)
  • semantic preflight: PASS, diff hash a9a5ff73f5c8c2d2cb326e984267ed0a5a1c85870506df3e56edddcc335db5f3

The local mo-tester invocation is still unavailable because this host has no Java Runtime; fresh CI is running on this head. Please re-review the updated exact head.

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

Re-reviewed exact head fb6a102 against 39225f5. APPROVE: no remaining blocking code finding.

Both previous blockers are closed. JsonQuote uses GetIsBinaryStringAt(row) after NULL/mask filtering, independently of UTF-8 validity. #28090 is merged (3d2e5c3), and git ancestry confirms its merge is contained in this head. The PR body's open-predecessor/old-head paragraphs are stale; please refresh them before landing.

Read the complete 11-file PR diff: quote escaping/UTF-8, row-aware shared template, declared expanding result bounds, prepared metadata versus runtime marker preservation, ENUM/SET JSON casts, wire metadata and SQL persistence tests. ASCII binary/invalid bytes, typed NULL, mixed/masked domains and text->binary->text COM_STMT_EXECUTE are covered. The CHAR(... USING utf8mb4) fixture correction preserves the intended domain check instead of weakening it. Runtime is a linear scan/output append; no new shared state, wait, background work or retained cache is introduced.

Evidence reused: author's focused exact-head domain/CHAR tests and direct-protocol boundary checks. Independently checked current CI: Linux UT, SCA and pessimistic multi-CN BVT pass. The proxy BVT log explicitly reports func_json_quote.test 54/54 passed (0.407s). Coverage UT fails in snapshot/feature-registry cases, including 'query feature registry for SNAPSHOT failed', not this changed quote path; the proxy job has other failures and is not globally green. I have not rerun native/MySQL tests or waited for CI.

This is exact-head implementation approval, not permission to bypass required CI/merge protections.

@aptend aptend 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.

Re-reviewed exact head fb6a102 against merge base 39225f5 and current main f72ca9e. APPROVE: no blocking issue remains.

The prior binary-domain counterexample is closed: JsonQuote performs the row-aware GetIsBinaryStringAt(row) rejection after NULL/mask filtering, so ASCII BINARY/VARBINARY/BLOB and invalid bytes fail while typed binary NULL and masked rows retain their contracts. The mandatory #28090 predecessor is merged as 3d2e5c3 and is an ancestor of this head.

I read the complete production, UT, protocol, and BVT diff and traced the text result through return-bound derivation, prepared-marker rebinding, wire metadata, CTAS persistence, and the ENUM/SET consumers that now cast the quoted text back to JSON. The JSON control-character escaping, UTF-8 validation, NULL behavior, direct/string-function composition, and full runtime prepared value are covered. Current-main changes touch several neighboring files, but the synthesized merge is conflict-free and the effective JSON_QUOTE changes remain intact; no shared state, wait, lifecycle, or unbounded retained resource is introduced.

Evidence reused at this exact head: Linux UT and SCA pass; pessimistic multi-CN BVT passes; the proxy BVT artifact reports func_json_quote.test 54/54 in 0.407s. The proxy job fails in the unrelated temporary_table_limitation.sql case, and coverage UT fails in snapshot/feature-registry tests outside this change. git diff --check and current-main merge-tree both pass. No local native test rerun is claimed.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

CI diagnosis for the exact head fb6a10200e86073c5954288c74718daca7f3c2c8:

  • Run 34144169055 has an independent UT Coverage failure in pkg/tests/issues/TestIssue23861FulltextSnapshotRestore: the snapshot feature-registry query failed before any JSON_QUOTE path was exercised.
  • The Compose PROXY job reports only test/distributed/cases/temporary/temporary_table_limitation.sql failures (99% success), also outside this PR's 11-file JSON_QUOTE/planner/protocol diff.
  • Utils Coverage is downstream (PREREQUISITES_READY=false) and is not an independent source failure.

I reviewed the exact changed-file boundary and the failed test paths; no direct or transitive JSON_QUOTE dependency reaches these snapshot/temporary-table cases. I am not rerunning the same current-head clusters: the required checks remain red and therefore unresolved/blocked_external, not fixed. A fresh green exact-head run is still required before merge.

@mergify

mergify Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-08 11:35 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-08 11:41 UTC · at 1f88818567d4aad2c006b64ae89f464557fe8cb3

This pull request spent 5 minutes 53 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

Pull request #28091 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

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 size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants