Skip to content

fix(json): preserve plain text in JSON_UNQUOTE - #28090

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-28042-json-unquote-text
Sep 7, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-28042-json-unquote-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 #28042

What this PR does / why we need it:

JSON_UNQUOTE treats SQL text as a JSON string only when the first and last bytes are both double quotes. Ordinary text, JSON-looking object/array/number text, one-sided quotes, and text with outer whitespace are returned unchanged. Fully quote-framed malformed strings and invalid UTF-8 still return errors, while typed JSON input keeps its canonical unquote behavior.

The result keeps the source CHAR/VARCHAR/TEXT capacity, including MEDIUMTEXT and LONGTEXT bounds, and always publishes utf8mb4_bin result metadata. CTAS therefore preserves both the source capacity and binary collation identity. Non-string scalar inputs such as DATE/TIME/numeric values are rejected before generic string casts can enter the passthrough path.

Binary domains remain visible through binding so NULL propagates as SQL NULL. Non-NULL BINARY, VARBINARY, BLOB, and binary-charset values reach execution and return the binary-domain error.

This head is based on upstream/main 4fdb9e91615f9fc37703039ae28a47849206d1d6, which includes #28089.

Validation on exact head 9a581373a942617ad536d8ecd3c5556c50b0d2ac:

  • JSON_UNQUOTE focused UT: PASS — .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s -run 'TestJsonUnquote' ./pkg/sql/plan/function
  • CTAS metadata focused UT: PASS — .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s -run 'TestBuildCTASPreservesJsonUnquoteTextBounds' ./pkg/sql/plan
  • Owning packages: PASS — pkg/sql/plan/function and pkg/sql/plan through mo-cgo-test
  • Final binary build: PASS — make build
  • Direct SQL smoke on an isolated single-CN instance: PASS — typed binary NULL and NULL BLOB propagate NULL; DATE input is rejected before implicit cast; non-NULL binary input returns the execution error; CTAS reports binary result collation and source bounds.
  • BVT fixture: test/distributed/cases/function/func_json_unquote.sql and .result updated for these cases. Local mo-tester execution is pending because this macOS host has no Java runtime; exact-head CI must supply the public-path BVT evidence.
  • git diff --check: PASS
  • mo-self-review: PASS
  • Semantic preflight schema v7: PASS semantic=PASS; diff hash a44f95565f5343965d3ab3e469d4eb451591b93c07ef2714e7847ec18923f99f

QA Required: yes. The SQL value, protocol metadata, domain-error, and CTAS contracts require fresh exact-head CI/BVT and QA verification before merge.

@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] 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/issue-28042-json-unquote-text branch from ffb2b21 to 2ded0e2 Compare September 4, 2026 06:59
@matrix-meow matrix-meow added size/M Denotes a PR that changes [100,499] lines and removed size/S Denotes a PR that changes [10,99] lines labels Sep 4, 2026

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

Deep review of exact head 9a581373a942617ad536d8ecd3c5556c50b0d2ac: request changes for one concrete string-domain correctness blocker.

[P1] Select binary rejection using the evaluated row's domain, not only the vector's static type

pkg/sql/plan/function/func_unary.go:1100-1104 chooses the binary-error callback once using types.StaticStringDomain. That is not the complete domain contract in current main: vector.GetIsBinaryStringAt(row) combines static type, runtime binary provenance and explicit text overrides.

Concrete input: a VARCHAR vector containing non-NULL bytes plain with runtime binary provenance. The static check is false, and the new passthrough at lines 1111-1112 returns plain successfully. A static VARBINARY containing the same binary value instead raises the intended binary-domain error. This is a reachable evaluator state, not a fabricated flag: ParamExpressionExecutor.Eval publishes GetPrepareParamIsBinaryString onto the result at pkg/sql/colexec/evalExpression.go:623; the user-variable evaluator does likewise at line 781. CASE/IF selected-row propagation is already tested by TestFlowControlPreservesSelectedBinaryStringRows, which produces a VARCHAR result with different binary/text domains per row.

The converse also matters: TestFlowControlPromotesSelectedStaticTextUnderBinaryResult covers a statically VARBINARY result whose selected value has an explicit text override. The new batch-wide callback rejects that text row, although the canonical row-aware API identifies it as text. Consequently the result/error can change across prepared parameter binding or flow-control materialization rather than following the selected value's semantics.

Please perform the domain check inside a row-aware evaluator, after NULL and select-list suppression, using GetIsBinaryStringAt(row). Preserve the typed-JSON branch and always publish text output metadata. Do not use a mutable callback counter, because the current unary template skips NULL/masked rows and evaluates a constant only once. Add mixed binary/text vectors (including a text override under static binary type), inactive binary branches, NULLs, and prepared text→binary→text rebinds. No SetIsBin shortcut is appropriate here.

Other reviewed aspects: first/last-byte quote framing preserves ordinary SQL text; malformed fully framed strings still parse/error; UTF-8 validation is explicit; CHAR/VARCHAR/TEXT capacity and utf8mb4_bin result metadata are preserved; numeric/date inputs are rejected before generic casts; allocation errors retain existing wrapper propagation. No separate resource-lifetime, concurrency or production-performance blocker was found. The UTF-8 check adds a linear scan but the passthrough avoids JSON parsing/materialization for ordinary text.

Evidence: exact-head source/type-matcher/template inspection and the existing runtime-domain producer/test contracts, plus the author's exact-head package/CTAS validation. I did not claim a fresh native SQL or MySQL reproduction. git diff --check passes; CI was not awaited. This is a value/error correctness issue, not a request to block solely on absent tests.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed XuPeng-SH's exact-head finding on b28269ef909fe1407fe4e5e1a5bd761769af8804.

  • JsonUnquote now rejects binary data using the evaluated row's vector.GetIsBinaryStringAt(row) after the unary template's NULL/selection barrier.
  • Added coverage for mixed binary/text rows, static VARBINARY text overrides, masked rows, typed JSON/text metadata, and prepared text -> binary -> text rebinds.
  • Kept the existing JSON branch, text result metadata, error text, and cached prepared plan unchanged.

Validation on the exact pushed commit:

  • GOWORK=off go test -mod=readonly -count=1 -timeout 120s -run '^TestJsonUnquote(RejectsInvalidFramedStringAndUTF8|TextTypeContract|RejectsNonStringDomain|BinaryDomainDefersErrorUntilValue|UsesEvaluatedRowStringDomain|PreservesPayloadBoundaryQuotes)?$' ./pkg/sql/plan/function: PASS
  • make thirdparties: PASS
  • make cgo: PASS
  • GOWORK=off .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s -run '^TestCOMStmtJsonUnquoteRebindExecutesWithWireStringDomain$' ./pkg/frontend: PASS
  • git diff --check, gofmt -d, and schema-v7 semantic preflight: PASS

The pushed commit is ready for re-review.

@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 b28269ef909fe1407fe4e5e1a5bd761769af8804. The previous row-domain blocker is closed; no further confirmed blocking issue found.

The new row-aware unary evaluator passes the actual row index, rather than a callback counter. NULL and inactive rows are suppressed before JSON_UNQUOTE's domain check; constant values retain one evaluation. GetIsBinaryStringAt(row) now handles both runtime binary provenance on VARCHAR and explicit selected-text overrides under a binary static type. The mixed-domain/masked-row fixtures and actual packet-decoder → rebind → expression-executor text/binary/text test address the previously demonstrated production paths, including cached-plan immutability and recovery after an error.

I checked the full diff, matcher and result typing, unary-template compatibility, and text versus typed-JSON paths. Ordinary UTF-8 SQL text is preserved without JSON canonicalization; only fully quote-framed text enters JSON parsing, preserving malformed-framed-input errors. Typed JSON still uses its existing decoding/unquote path. CHAR/VARCHAR/TEXT bounds and utf8mb4_bin result metadata are covered by function and CTAS tests; binary NULL propagates and non-NULL binary values fail at evaluation.

The shared wrapper preserves the previous callers' callback semantics. UTF-8 validation adds a linear scan, but ordinary text avoids JSON parsing/materialization; no new persistent cache, asynchronous ownership, or unbounded lifecycle state is introduced. No concrete new performance or resource blocker identified.

Validation in this round: complete source/diff and test inspection, prior runtime-domain evidence, and git diff --check. I did not freshly run native UT/BVT, race, or a live MySQL differential test and did not wait for CI. The protocol fixture tests packet decoding and real expression execution, not a complete client/server handshake.

@mergify mergify Bot added the queued label Sep 7, 2026
@mergify

mergify Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-07 11:04 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-07 11:08 UTC · at 64e3dbd0082d61b060b5a7fccbf2f1d5669fc5d3

This pull request spent 3 minutes 38 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 #28090 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.

Failing checks:

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

@XuPeng-SH
XuPeng-SH merged commit 3d2e5c3 into matrixorigin:main Sep 7, 2026
20 of 22 checks passed
@mergify mergify Bot removed the queued label Sep 7, 2026

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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants