Skip to content

fix(frontend): preserve bytes and binary types in saved query results - #32269

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-31535-main-955cb5ec
Nov 6, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-31535-main-955cb5ec

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Nov 5, 2026 •

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 #31535

What this PR does / why we need it:

Saving a frontend result set through
convertRowsIntoBatch
rendered every non-string VARCHAR/TEXT cell with fmt.Sprintf("%v", ...), so
engine-extracted []byte cells — the presentation DATA BRANCH DIFF produces
for VARCHAR and VARBINARY columns — became textual numeric lists such as
'[228 184 173 230 150 135]'. The same result-metadata conversion mapped every
VAR_STRING column to VARCHAR, so VARBINARY diff columns also lost their
binary logical type in the saved result. RESULT_SCAN then returned the
corrupted values and INSERT ... SELECT persisted the wrong data.

Root cause

  • convertRowsIntoBatch type-asserted VARCHAR/TEXT row values to string and
    formatted anything else with fmt.Sprintf("%v", ...); the diff pipeline
    (data_branch_output.go -> extractRowFromVector) hands over []byte
    cells for VARCHAR/VARBINARY and []float32 cells for VECF32 family columns.
  • mysqlColDef2PlanResultColDef ignored the column charset and mapped every
    MYSQL_TYPE_VAR_STRING/MYSQL_TYPE_VARCHAR result column to T_varchar,
    including VARBINARY columns, which publish VAR_STRING with the binary
    protocol charset.

Changes (all in matrixorigin/matrixone)

  • pkg/frontend/util.go: convertRowsIntoBatch renders VARCHAR/TEXT/VARBINARY
    cells through the new textRowValueBytes helper; string/[]byte cells keep
    their exact bytes, vector cells ([]float32/[]float64/[]BF16/
    []Float16/[]int8/BlockScaledValue) render with the same presentation the
    client sees (types.ArrayToString / types.BlockScaledToString), and other
    scalars keep the existing fmt.Sprintf rendering so current consumers are
    unchanged. NULL rows still produce NULL slots.
  • pkg/frontend/util.go: mysqlColDef2PlanResultColDef maps VAR_STRING/VARCHAR
    columns carrying the binary protocol charset to T_varbinary
    (MaxVarBinaryLen), and convertRowsIntoBatch gained a T_varbinary case, so
    binary columns keep raw bytes and binary metadata in the saved result.
  • pkg/frontend/util_test.go: new focused UTs.
  • test/distributed/cases/git4data/branch/diff/diff_saved_text_binary.sql and
    .result: new BVT for the issue's user-visible contract.

Issue-to-test proof

  • Test_convertRowsIntoBatchVarStringBytesAndBinaryType covers multibyte
    VARCHAR bytes (中文), raw VARBINARY bytes FF 00 0A, NULL vs empty,
    embedded NUL/non-UTF-8 counterexamples, and the saved binary column type
    (65/T_varbinary). On the parent base it fails (saves '[228 184 173 230 150 135]' bytes and types the binary column 61/T_varchar); after the fix it
    passes — recorded red/green evidence for [Bug]: saved DATA BRANCH DIFF corrupts text and binary values returned by RESULT_SCAN #31535.
  • Test_convertRowsIntoBatchVectorTextPresentation covers the issue-comment
    VECF32 case (saves "[2, 2]" display text rather than the Go %v form
    [2 2]); red on base, green post-fix.
  • Test_convertRowsIntoBatchBlockScaledAndNarrowVectorText (added after the CI
    changed-code coverage gate flagged the helper's remaining branches) covers
    BF16/Float16/int8 vector cells (display text such as "[2, -0.5]"), a
    block-scaled (vecf8) cell saved exactly as MysqlResultSet.GetString
    renders it for the client, and an unparseable block-scaled cell that keeps
    the pre-fix %v presentation (empty text: the fmt.Stringer path renders a
    corrupt cell as "") instead of failing the whole saved result.
  • Runtime repro of the exact issue scenario on a standalone instance built from
    this tree: result_scan(@qid) returns v='中文' and HEX(bin)='FF000A', and
    INSERT INTO copied SELECT ... FROM result_scan(@qid) persists those values;
    the source table is untouched; a VECF32 diff reads back [3, 4], identical to
    the direct output.
  • New BVT diff_saved_text_binary (direct diff, result_scan readback,
    INSERT ... SELECT, NULL-filter and source-table checks) passes 100% under
    the repo's mo-tester (21/21 statements). The generated .result was
    inspected against the intended semantics before submission.

Test commands

  • Red (parent base): .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -v -run 'Test_convertRowsIntoBatchVar|Test_convertRowsIntoBatchVector' ./pkg/frontend/ — both new tests fail.
  • Green (this branch): same command passes; regression selection
    -run 'Test_saveQueryResultMeta|Test_mysqlColDef2PlanResultColDefIntegerSignedness|Test_convertRowsIntoBatch'
    also passes all existing conversion/decimal/error/unsigned round-trip and
    result-save tests (go test via the CGo wrapper).
  • go vet -mod=readonly ./pkg/frontend/ with the documented CGo environment:
    clean. gofmt clean on both changed Go files.
  • Coverage follow-up: .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -v -run 'Test_convertRowsIntoBatchBlockScaledAndNarrowVectorText' ./pkg/frontend/
    passes; with it, every changed block of textRowValueBytes is exercised
    (the CI coverage job had measured 70%: 14/20 changed blocks, leaving the
    BF16/Float16/int8/BlockScaledValue branches untested).
  • BVT: bash run.sh -p <...>/git4data/branch/diff -m run -r 100 -i diff_saved_text_binary — SUCCESS RATE 100%.

Residual risk

  • The binary-charset remap applies only to VARBINARY-shaped result columns;
    hand-built frontend result sets default to charset 0 and UUID/T_Rowid/T_enum
    VAR_STRING columns publish text charsets, so their saved types are unchanged
    (covered by existing tests passing).
  • Saved vector values are persisted as their display text, matching what the
    client-visible result presents; re-materializing a vector type requires an
    explicit CAST.
  • Unsupported result column types (JSON/BIT/BLOB) keep their existing
    unsupported-type save error, tracked separately in [Bug]: DATA BRANCH DIFF fails on JSON, BIT and BLOB when saving query results #31534.
  • Broader suites (full pkg/frontend run, whole distributed BVT) remain for CI;
    the focused red/green and regression runs above cover the changed conversion
    path and its existing consumers.

Related to #31535

Saving a frontend result set through convertRowsIntoBatch rendered every
non-string VARCHAR/TEXT cell with fmt.Sprintf("%v", ...). Engine-extracted
[]byte cells - the presentation DATA BRANCH DIFF produces for VARCHAR and
VARBINARY columns - therefore became textual numeric lists such as
'[228 184 173 230 150 135]'. mysqlColDef2PlanResultColDef also mapped every
VAR_STRING column to VARCHAR, so VARBINARY diff columns lost their binary
logical type in the saved metadata. RESULT_SCAN returned the corrupted
values and INSERT ... SELECT persisted them.

- convertRowsIntoBatch now renders VARCHAR/TEXT/VARBINARY cells with
  textRowValueBytes, which keeps the exact bytes for string/[]byte cells,
  uses the client-visible presentation (types.ArrayToString /
  BlockScaledToString) for vector cells, and leaves other scalars on their
  existing fmt.Sprintf rendering, so existing consumers are unchanged.
- mysqlColDef2PlanResultColDef maps VAR_STRING/VARCHAR columns carrying
  the binary protocol charset to T_varbinary, and convertRowsIntoBatch
  gained a T_varbinary case, so binary columns keep raw bytes and binary
  metadata.

Proof:
- Test_convertRowsIntoBatchVarStringBytesAndBinaryType and
  Test_convertRowsIntoBatchVectorTextPresentation fail on the parent base
  (saved '[228 184 173 230 150 135]' bytes, varbinary column typed 61) and
  pass after the fix; the existing conversion/decimal/error/unsigned and
  result-save metadata tests all still pass, and go vet is clean.
- On a standalone instance built from this tree the issue's exact
  reproduction returns v='中文', HEX(bin)='FF000A' from result_scan and the
  INSERT ... SELECT copy persists those values; a VECF32 diff control reads
  back '[3, 4]' identical to the direct output.
- New BVT diff_saved_text_binary (sql + checked result) passes 100% under
  mo-tester.

Related to matrixorigin#31535
The CI changed-code coverage gate measured the textRowValueBytes helper at
70% (14/20 changed blocks): the []types.BF16, []types.Float16, []int8 and
types.BlockScaledValue branches had no coverage.

Add Test_convertRowsIntoBatchBlockScaledAndNarrowVectorText: BF16/Float16/
int8 vector cells and a vecf8 block-scaled cell must save the same display
text the client-visible result presents (asserted with MysqlResultSet.GetString
as the oracle), while an unparseable block-scaled cell keeps the pre-fix "%v"
presentation (empty text, since BlockScaledValue's fmt.Stringer renders a
corrupt cell as "") instead of failing the whole saved result.
@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 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 590331d468eeac3dabb110a3aea3d505dd19d878

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 590331d468eeac3dabb110a3aea3d505dd19d878

Assessment: approve

The fix preserves saved text/binary bytes and binary metadata through the existing result-save path, and reuses the protocol's vector formatters. The changed conversion and public readback/copy contracts are covered without adding state or another persistence mechanism.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Reviewed all four changed files, the binary golden, both discussion entries and linked issues 31535/31534; traced branch extraction, protocol rendering, metadata, save and RESULT_SCAN consumers.

  • Local audit passed: clean frozen source, patch identity, gofmt for both Go files, binary-golden byte/metadata/copy oracles and discussion coverage. Receipt checks/1793919069942493664-2.json and audit.log retained.

  • Reused frozen exact-head successful build, UT/SCA/coverage and PROXY/PESSIMISTIC BVT checks. Author reports focused conversion red/green, regression/vet and 21/21 public BVT execution.

Limitations:

  • No local CGo frontend tests or live SQL/BVT execution; raw CI/author runtime logs are not supplied. Unsupported JSON/BIT/BLOB saving remains the separately scoped issue 31534.

@mergify mergify Bot added the queued label Nov 5, 2026
@mergify

mergify Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as 2746f81 at Fri 6 Nov, 00:23 UTC

1 h 31 min in the queue, 1 h 9 min of it CI.

So far

  • ✅ Entered the queue Thu 5 Nov, 22:52 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged Fri 6 Nov, 00:23 · 2746f81 · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
ci — 3b891a69 Deployed Nov 5, 2026 by mergify[bot]
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