Skip to content

fix(load): keep empty ENUM member and empty SET distinct from NULL - #29854

Merged
XuPeng-SH merged 9 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/load-empty-enum-set
Oct 11, 2026
Merged

XuPeng-SH merged 9 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/load-empty-enum-set

Conversation

@MatrixAdventurer

@MatrixAdventurer MatrixAdventurer commented Oct 11, 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 #29840

Fixes #29840

What this PR does / why we need it:

CSV/JSONLINE LOAD preserves valid empty SET and declared empty/whitespace ENUM members while explicit NULL markers and NULLIF mappings still win. Logical SET is identified before numeric empty-to-zero or LOCAL numeric-prefix normalization; declared ENUM members survive trimming. The loader membership predicate avoids allocating discarded conversion errors and leaves value conversion to the existing type parser.

Tests compare INSERT with CSV/JSONLINE, requested parallel and LOCAL modes, exact ENUM ordinals and SET bitmaps, explicit NULL and NULLIF mapping. SQL mode is saved/restored. A separate test-only commit starts TestCrossTargetUpgradeRecovery's five-minute SQL budget after initial successful cluster startup, avoiding expiry while waiting for fixture admission. Cleanup remains registered before construction/start assertions, and restarts share one recovery budget.

Validation

Full external normal/race tests; incremental external/embed SCA; all four cross-target recovery scenarios in normal, race and coverage modes; public LOAD comparison: 39/39, zero ignored/failed/abnormal. All four recovery subcases pass in normal (109.93s), race (110.5s) and coverage (87.53s) runs. Requested parallel on small fixtures does not establish split-reader execution; no Parquet SET claim.

Rebased onto main 42d42546fd2c2b2449cb81cea47f81d300139753 (the requested base snapshot). Current GitHub CI is reported separately from local validation.

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

@CLAassistant

CLAassistant commented Oct 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@MatrixAdventurer

Copy link
Copy Markdown
Contributor Author

End-to-end verification

Setup: built mo-service (make build) from main (d7752ff) and from this branch, launched single-node with ./mo-service -launch etc/launch/launch.toml, client mysql -h127.0.0.1 -P6001 -uroot -p111.

Table (id int pk, e enum('red','中文',''), s set('a','中文')), rows red/a, ''/'', 中文/a,中文, NULL/NULL. The table shows row 2 (e, s, e IS NULL, s IS NULL):

Path main this PR
INSERT (reference) '' '' 0 0 '' '' 0 0
LOAD CSV NULL NULL 1 1 '' '' 0 0
LOAD JSONLINE (object) NULL NULL 1 1 '' '' 0 0
LOAD CSV PARALLEL 'true' NULL '' 1 0 '' '' 0 0

Explicit \N / JSON null (row 4) stays NULL on both builds.

BVT (mo-tester run.sh -n -g): test/distributed/cases/load_data 1234 total / 0 failed, cases/dtype 7744 total / 0 failed. The numbers match the main baseline.

@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 234f6ee42bdb6f2ce7ffe026baab8b78c9966341 against base/merge-base 4022729da24d71b082c22b52aaed3faba2b77ea5: REQUEST_CHANGES. Two silent wrong-result cases remain in the issue's explicitly requested acceptance boundary, and the new membership check adds avoidable per-field allocation cost. Details and concrete reproductions are inline.

Design: the existing external reader should identify explicit NULL and preserve the logical ENUM/SET input; the existing type parser should own its interpretation. This patch adds an exception after two generic physical-type transformations (trim and numeric zero-fill). Those earlier assumptions still apply to ENUM / SET-as-uint64, so the new branch does not systematically fix the contract. No new state machine, storage path or concurrency owner is introduced, and a separate architecture document is unnecessary for this focused fix. Parquet SET support is explicitly excluded by the author and is not being reopened here.

Validation performed on this head: the author's focused tests pass; reviewer owner-level probes pass strict-serial empty SET and all explicit-NULL controls, but fail requested-parallel and LOCAL non-strict empty SET, plus a declared whitespace ENUM member. A real embedded cluster and authenticated MySQL connection reproduce the same wrong readbacks through LOAD DATA. Native INSERT is the independent control: it preserves empty SET and the whitespace ENUM member. The public probe finished in 8.61s (package 10.405s): strict-serial control passes; the other three subcases fail their value assertions after LOAD succeeds. The small PARALLEL 'true' case proves requested-parallel initialization, not split-file/multi-worker execution. No timing, resource-leak or race claim is inferred from this test.

Required test closure: commit a small SQL regression through actual CSV/JSONLINE LOAD and readback with native INSERT controls, including the two counterexamples, explicit NULL/null_map semantics and the applicable LOAD modes. The new 86-line unit test uses decimal256ExternalParam, whose ExternType is EXTERNAL_TB; switching the format label does not execute either reader or LOAD initialization. That is why it misses the zero-fill branch. Its whitespace-equals-empty assertion also misses a schema that declares both members. There is no committed BVT delta. The author's manual common-value SQL evidence is useful, but neither it nor unchanged load_data/dtype cases protects these changed contracts in CI.

Performance evidence: identical getColData benchmark, same fixture/vector reuse/NULL oracle, three 300ms samples on Go1.27.1 Darwin/arm64 Apple M4; the only base substitution is external.go from the merge-base via Go overlay. Base: 29.52-30.02 ns/op, 0 B/op, 0 allocs/op. Head: 804.5-815.1 ns/op, 760 B/op, 14 allocs/op. This measures the empty-field conversion path only, not end-to-end LOAD throughput or TP/prepared-statement latency.

Change accounting: implementation +17/-1; tests +86/-0; documentation 0. Both production hunks and the entire new test were reviewed, including reader/Prepare/cast consumers and the native type-parser counterpart. No prior substantive review threads exist to resolve. No production source was changed and no subagents were used.

Comment thread pkg/sql/colexec/external/external.go Resolved
Comment thread pkg/sql/colexec/external/external.go Resolved
Comment thread pkg/sql/colexec/external/external.go Resolved
@MatrixAdventurer

Copy link
Copy Markdown
Contributor Author

Addressed review 5482067478 in 7c3f114 (inline replies on all three threads).

  • Production: pkg/sql/colexec/external/external.go only.
    • Logical SET is classified before the numeric zero-fill and the non-strict numeric-prefix rewrite.
    • A declared ENUM member (including ' ' and '') is not trimmed.
    • The membership check is allocation-free (isEnumMember); ParseEnum is no longer called on the empty/NULL path.
  • Committed SQL regression test/distributed/cases/load_data/issue_29840_load_empty_enum_set.{sql,result} plus a 6-line CSV and a 6-line JSONLINE fixture. Table e ENUM(' ','red',''), s SET('0','a'). It covers empty ENUM member, whitespace ENUM member, empty SET, explicit NULL (\N / JSON null), member '0', and '0,a'. It runs:
    • a native INSERT control;
    • CSV strict serial;
    • CSV PARALLEL 'true';
    • CSV LOCAL with sql_mode='';
    • JSONLINE serial;
    • JSONLINE PARALLEL 'true'.
      It ends with a per-mode row-diff against the INSERT control.
  • Unit test reworked to use ExternType_LOAD in strict, parallel and LOCAL non-strict modes, with the two-member ENUM schema.
  • Verification on a rebuilt mo-service:
    • New case: previous head 27/33. The diffs vs INSERT were csv 1, csv_par 2, csv_local 3, jl 1, jl_par 2 rows. This head: 33/33, 0 diffs in every mode.
    • BVT load_data 1267 total, 0 failed; dtype 7744 total, 0 failed (main baseline: load_data 1234 / dtype 7744, 0 failed).
    • UT pkg/sql/colexec/external and pkg/container/types pass.

@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 follow-up review of ebf1975ec815cd911c837b15fbf0ed7da8930c23 against base/merge-base f09d4788fd4d1aa30aae0e2f49d014589e7566c0: REQUEST_CHANGES — two P2 blockers.

  1. Valid Unicode-whitespace SET members still silently become another member. The ASCII-only guard is narrower than strings.TrimSpace. Real CSV/JSONLINE LOAD and both requested-parallel variants store plain a (bitmap 32) instead of the declared NBSP/ideographic-space members (bitmaps 2/4/8). Details and controls are added to the existing SET preservation thread. The same exact-base probe fails: this is an incomplete repair within #29840's stated contract, not a new correctness regression.
  2. The new padded-SET check adds discarded-error work to accepted input. For SET('a','b'), input " a " still yields bitmap 1, but real conversion changes from ~60 ns/16 B/1 allocation to ~913 ns/688 B/15 allocations per field. The new inline comment contains the base/head experiment and repair direction. This is a new local conversion regression; no whole-LOAD, TP or prepared-latency multiplier is claimed.

Design: keeping logical SET out of physical-uint64 normalization, preserving declared ENUM members, and retaining explicit NULL/null-map priority are appropriate. The external reader owns field normalization; the existing type parser owns member/bitmap semantics. The new SET guard should align with the transformation's full domain and avoid creating errors merely to answer a membership question. No new state machine, storage or execution path is warranted. No separate architecture document is needed for this focused fix.

Previous comments: the first three findings (SET numeric rewrite, ENUM whitespace, empty-ENUM allocation) remain fixed/resolved. The fourth SET whitespace finding is only partially fixed: its ASCII witness now passes, but the Unicode witness above does not. Keep that thread open.

Validation and test quality: inspected all six changed files and their actual reader/cast/parser consumers. Reused exact-head CI run 38141361383: the compose artifact explicitly runs the changed SQL case, 39/39 successful, zero failed/ignored/abnormal; the UT checkpoint selects the external package in the successful race stage. The regression's explicit values/ordinals/bitmaps, native INSERT control and SQL-mode restoration are useful, but do not cover these two counterexamples. Fresh public probes use the real embedded server and MySQL frontend, preserve all rows, and fail 12 SET value assertions while adjacent controls pass; exact-base comparison distinguishes historical failure from new regression. Small requested-parallel fixtures do not establish split-file/multiworker coverage. Parquet SET remains outside the agreed scope.

Increment reviewed: implementation +50/-4; Go tests +186; SQL case +50, expected output +98, fixtures +12; documentation 0. The recovery fixture repair is now in the base and is not counted in this PR. No production changes or subagents were used in this review. Disclosure: I contributed to an earlier repair round; this is follow-up review with fresh probes, not independent third-party certification.

Comment thread pkg/sql/colexec/external/external.go Resolved

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

APPROVE at ebf1975 against base f09d478. No confirmed blocker.

Reviewed the six-file LOAD change. Logical SET is recognized before numeric empty-to-zero and LOCAL prefix rewriting; a declared ENUM/valid padded SET input is preserved before trimming. Explicit NULL markers and NULLIF mappings retain precedence. Conversion stays with the existing ENUM/SET parsers, and undeclared empty ENUM input keeps the prior NULL behavior. The membership predicate avoids allocating discarded conversion errors on the ordinary path.

Tests use exact ordinals/bitmaps, whitespace and member0 controls, NULL/NULLIF and INSERT-versus-LOAD comparisons across CSV/JSONLINE, LOCAL and requested parallel modes, with saved/restored SQL mode and teardown. Requested parallel on small fixtures is not counted as split-reader validation. Current-head required CI, UT/SCA/coverage and proxy/pessimistic BVT are green; author normal/race/public39/39 evidence was reused, not rerun locally. Diff whitespace checks pass. Single-empty-member type-domain admission and Parquet SET behavior are not claimed by this fix.

Address review on matrixorigin#29854:
- isPaddedSetInput now checks the boundary runes with unicode.IsSpace,
  the same whitespace domain strings.TrimSpace removes, so declared
  members such as '\u00a0a', '\u3000a' and 'a\u00a0' are not trimmed into 'a'.
- Membership is answered by the new non-throwing types.MatchSetName
  (same descriptor/parseName as ParseSet) instead of ParseSet+discarded
  moerr; parseName walks items with strings.Cut so it does not allocate.
- UT: Unicode SET block across strict/parallel/local-nonstrict, padded
  accepted/fallback inputs in the zero-alloc guard. SQL case: NBSP/U+3000
  members (rows 7-10) for INSERT vs CSV/JSONLINE LOAD modes.
@MatrixAdventurer

Copy link
Copy Markdown
Contributor Author

@XuPeng-SH both P2s from review 5483691319 are addressed in c75a281 (details in the two threads): the SET preservation guard now covers Unicode whitespace like TrimSpace, and padded input is matched without building errors (padded fallback 688 B / 15 allocs -> 0 B / 0 allocs). Case 39/39 (previous head 32/39), load_data 1289/0 failed, dtype 7712/0 failed. Could you take another look?

@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 follow-up review of c75a281a08c34e1e9e4614993195a94f365198d4 against merge-base f09d4788fd4d1aa30aae0e2f49d014589e7566c0: APPROVE. Both remaining P2 findings are closed, and the earlier three fixes remain intact.

Design: logical SET is classified before physical uint64 normalization, explicit NULL/NullMap retains priority, and declared ENUM/SET members are preserved before lossy trimming. The padding guard now covers exactly unicode.IsSpace, including NBSP and ideographic boundaries. Recognition delegates to the existing SET descriptor/parseName owner via MatchSetName; it neither duplicates the parser/cache nor constructs a discarded conversion error. The strings.Cut traversal preserves Split's item boundaries (including empty/trailing items) while removing its temporary slice. Numeric fallback, invalid bitmap checks and case/trailing-ASCII normalization remain owned by ParseSet. This is a focused behavior repair, not a new lifecycle or architecture requiring a separate design.

Fresh local evidence: reran the previous real embedded-cluster/MySQL-frontend counterexample unchanged on this exact head. CSV, requested-parallel CSV, JSONLINE and requested-parallel JSONLINE now all match independently inserted values for six ASCII/Unicode boundary members, with exact ENUM ordinals and SET bitmaps. All four subcases pass (test body 8.50s; package 11.161s), with ordinary cleanup completing. The same probe's previously recorded exact-base failures remain valid counterfactual evidence; no claim that these historical wrong results were introduced by this PR. Focused external/types tests pass, including empty/NULL/mapped-NULL and three LOAD modes.

Performance closure: reused the exact real getColData benchmark with a reused vector and bitmap/NULL oracle, three 300ms samples. Both unpadded a and accepted padded fallback a now report 0 B/op, 0 allocs/op. The previous head's padded path was 688 B/op/15 allocations; the discarded-error regression is gone. Timing samples are not used to claim end-to-end LOAD or TP speedup. An extra nonthrowing lookup remains only for padded SET input and buys preservation of otherwise lossy valid members; no new cache or per-row error object is warranted or present.

Public regression evidence: exact-head successful CI run 38158699646, pessimistic BVT execution artifact selects issue_29840_load_empty_enum_set.sql: 39/39, zero failed/ignored/abnormal. Read all SQL/resource/result additions: exact labels/ordinals/bitmaps, NULLIF precedence, five LOAD variants and SQL-mode restoration are meaningful oracles. The explicit row readbacks also protect cardinality beyond the inner-join parity count. Small fixtures establish requested-mode semantics, not split-reader execution; no Parquet SET claim.

Accounting: implementation 2 files +74/-6; Go tests 1 file +206/-0; SQL/results/resources 4 files +197/-0; documentation 0. All changed hunks and direct parser/loader consumers reviewed. No production edits or subagents.

@mergify mergify Bot added the queued label Oct 11, 2026
@mergify

mergify Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-11 23:20 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-11 23:23 UTC · at 5e40301a70bb7298bc1f9783ee9dba0523dc648c

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

Reason

Pull request #29854 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.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

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
ci — 5e40301a Deployed Oct 12, 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.

[Bug]: CSV/JSONLINE LOAD silently converts valid empty ENUM/SET values to NULL

5 participants