Repository navigation
fix(plan): honor SET NULLIF and reader options in LOAD DATA INLINE - #32198
Conversation
LOAD DATA INLINE rebuilt its execution ExternParam from a hand-written subset of the parsed options, dropping the SET NULLIF sentinel map and the LINES options that file-backed loads publish through the serialized source param, so inline loads silently stored raw values for supported SET mappings, lost the line prefix, and rejected their input. INLINE now shares the same serialized source-param channel as INFILE and restores it at execution, preserving the established inline escape-byte default. Prepared statements keep normalizing and re-deriving those rules on every replan: the transport serializes from a stripped copy of consumed column expressions, while the row-variable wrapper stays attached to the statement so a rebuilt plan keeps the row-variable scan column and the assignment projection instead of falling back to the target default (prepared inline loads that change sql_mode between PREPARE and EXECUTE). CREATE EXTERNAL TABLE shares the same InitNullMap normalization and published the live statement param into its catalog CREATE property metadata. With the wrapper now retained, that property carried a non-reconstructible expression interface and made SHOW CREATE TABLE and every scan of the new table fail on the json decode. The publish site now serializes from a stripped copy too, restoring the base metadata shape: the definition keeps reader options and the sentinel map, and never persists an expression interface. Related to matrixorigin#31232
9a297eb to
40a813f
Compare
…nt-neutral The recorded show-create result embedded an environment-specific INFILE rendering, so the pessimistic BVT failed on CI where the absolute runner path differs. Switch both show create table assertions to mo-tester -- @regex directives (repo convention, e.g. dml/show/show_create_table.sql) and drop the empty-FILEPATH rendering from the recorded result.
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: a3a865e8f2c1ebc94a8aa30575166b5e0ab3fe26
Assessment: approve
The fix reuses the existing source-parameter transport for INLINE, keeps the retained AST replayable, and preserves external-table metadata decoding. No actionable correctness or design defects found.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed all 24 changed files and affected planner, prepared-rebuild, reader and catalog consumers.
-
Reused successful frozen-head CI: native build, Ubuntu UT, arm64 SCA, coverage, and PROXY/pessimistic multi-CN BVT.
-
Local Java probe passed all 12 regex directives and 30 positive/negative assertions.
-
Source, patch and formatting audit passed; four receipts and both discussion entries reconciled. Checkout unchanged.
Limitations:
-
Raw CI/author execution logs were unavailable; Go and SQL/BVT suites were not rerun locally.
-
The local Java probe validates assertion syntax and guards, not server behavior.
❌ Left the queue · checks failed1 h 29 min in the queue, with no time running CI. So far
The failure is in this pull request. It failed tested alone on top of Reason The merge conditions cannot be satisfied due to failing checks
To get back in the queue
Merge conditions not met when it left the queue
Requeue requested — the merge queue status continues in this comment ↓. 2 merge conditions met
Times in UTC · dashboard · how the merge queue works |
|
Unresolved unrelated CI blockers tracked in existing issues The failed required check
The failed jobs were rerun once for attempt 1 ( |
✅ Merged into
|
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed all 24 changed files and the LOAD planning, assignment validation, retained-AST replay and external-table metadata consumers. INLINE now reconstructs reader options through the shared serialized-source channel while retaining its established escape-byte behavior. Copy-based publication keeps PREPARE's column/assignment state replayable, and external-table properties exclude non-decodable expression interfaces without losing column NULLIF mappings.
The tests independently cover actual loaded values, file/inline controls, omitted/custom escapes, unsupported SET rejection, mode-driven prepared replans and external-table SHOW CREATE/readback. No blocking findings. Reused latest-head green CI (including both BVT modes) and the source-bound focused/owning-package evidence in the PR; no local tests were rerun.
What type of PR is this?
Which issue(s) this PR fixes:
Related to #31232
What this PR does / why we need it:
LOAD DATA INLINEsilently ignored supportedSET ... NULLIFclauses andstored the raw values, and dropped
LINES STARTING BY(input rejected with20101), while the byte-identical file-backed
LOAD DATA INFILEhonored everyoption. The same loss applied to
FORMAT='jsonline'INLINE loads, to preparedINLINE loads re-planned across a session
sql_modechange, and — after thetransport fix — to
CREATE EXTERNAL TABLEdefinitions whoseSETclauseuses a row variable.
Root cause
serialize the parsed
tree.ExternParamintoTableDef.Createsqlforfile-backed scans, but
getExternParamrebuilt INLINE parameters by handfrom a small subset (
Data,Format,IgnoredLines,Fields,JsonType),dropping
NullMap(theSETsentinel rules) andTail.Lines(prefix /terminator options).
getColDataappliesparam.Extern.NullMapwhenreading, so INLINE loads read rows with the mapping missing.
keep repeated planning of the same retained AST correct: the column
NULLIFexpressions are consumed into the map during normalization, and anaive serializer left a half-consumed AST that a rebuilt plan could not
re-normalize; row-variable (
NULLIF(@v, literal)) wrappers similarly hadto stay attached so every replan re-derives the
__mo_load_user_var_scancolumn and the assignment projection instead of falling back to the target
column DEFAULT.
CREATE EXTERNAL TABLEcalls the sameInitNullMapnormalization and then published the live statement param viajson.Marshalinto the catalog CREATE property. Retaining therow-variable wrapper put a live
tree.Exprinterface into that property —encoding/jsoncannot reconstruct it — soSHOW CREATE TABLEand everyscan of the new table failed with
json: cannot unmarshal object ... ExternParam.Tail.Assignments.0.Expr of type tree.Expr.Exact changes
pkg/sql/plan/bind_load.go+pkg/sql/plan/build_load.go: the LOADplanners serialize a source param through the existing planning channel
(
marshalLoadSourceParam) for INLINE and INFILE alike; serialization workson a copy, stripping consumed column expressions so the parsed statement
stays replayable;
InitNullMapkeeps the row-variable wrapper attached andrecognizes an already-normalized statement by the explicit
hasUnconsumedColumnNullIfscan.pkg/sql/compile/compile.go:getExternParamunconditionally deserializesthe saved source param and restores the INLINE payload/escape byte from the
plan (
ExternScan), so both scan types honor identical parsed options.pkg/sql/plan/build_ddl.go: newmarshalExternalTableParam— the CREATEEXTERNAL TABLE publish site serializes from a stripped copy (
ColumnListdropped, assignment
Exprs null), restoring the base published metadatashape (reader options + sentinel map, no expression interface) while the
statement keeps its expressions for the rest of its planning session.
pkg/sql/planandpkg/sql/compileand four BVTcases under
test/distributed/cases/load_data/(details below).Issue-to-test proof
SET flag=NULLIF(flag,0)stores NULL for0(file-backed pairdoes the same); the no-SET control keeps raw values; unsupported SET stays
rejected with 20105 and inserts nothing —
UT
TestInlineLoadSerializesSourceParam,TestGetExternParamReconstructsInlineSourceParam; BVTissue_31232_inline_load_options(50/50).jsondata='object') applies the same mapping; prefixLINES STARTING BY,IGNORE n LINESand explicitESCAPED BYcompose withit; the inline omitted-escape default (backslash byte is literal data)
stays byte-compatible —
UT
TestInlineLoadEscapeBytePlanning,TestInlineLoadEscapeByte; BVTissue_31232_inline_escape(35/35).sql_mode(plan reused) and withONLY_FULL_GROUP_BYflipped betweenPREPAREandEXECUTE(plan rebuilt)both keep the mapping: column form and row-variable form
(
(id, @v)+SET payload=NULLIF(@v,'sentinel')never substitutes thetarget DEFAULT) —
UT
TestSerializedSourceParamSurvivesReplan,TestSerializedSourceParamSurvivesUserVariableReplan(both planner surfaces);BVT
issue_31232_prepare_rebuild(26/26).CREATE EXTERNAL TABLE ... SET flag=NULLIF(@v,'sentinel')(base-acceptedform) stays fully usable:
SHOW CREATE TABLErenders,SELECTscans (therow-variable form is inert at scan time — external tables have no load
column list — so raw values read back), DROP leaves no residue; the column
form keeps its live sentinel mapping —
UT
TestCreateExternalTableParamMetadataRoundTrips; BVTissue_31232_external_table_metadata(16/16, run twice).pre-fix code (e.g. the external-table witness CREATE succeeded then
SHOW CREATE/SELECT failed with the json decode error; the inline SET stored
(1,'alpha',0)where NULL was expected).Test commands
Focused (exact selections,
mo-cgo-testwrapsgo test):Unfiltered owning packages:
BVT (
mo-tester, comparison mode;pathpoints at the case file):All of the above passed on the committed source (focused: ok; packages: both
okwith no failing tests; BVT: 50/50, 35/35, 26/26, 16/16×2 at 100%).Residual risks
LOAD DATA SETremains limited toNULLIF(column, literal)/NULLIF(@variable, literal)(20105 otherwise); this PR does not extend thesupported SET grammar.
at scan time (no load column list exists); the column form is what scans
apply.
SHOW CREATE TABLEfor read-only external tables masksFILEPATH(pre-existing behavior, unchanged).
pkg/sql/plan(
apply_indices_score_expr_test.go,visit_plan_rule_test.go) arecommitted-at-base drift and are intentionally untouched by this PR.
load_data_set_null.sqlandload_data_jsonline.testcarry older metadata expectations that this PRdoes not regenerate; broader suite validation is left to repository CI as
usual.
Rebase note (conflict resolution against upstream
main)Upstream
mainrefactored the LOAD prescan/serialization into a sharedprepareLoadScanhelper (pkg/sql/plan/bind_load.go, used by both plannersurfaces), and widened
validateLoadSetAssignmentswith atableDefargument (hidden-storage-column rejection). The rebase keeps upstream's
prepareLoadScanstructure and resolves it semantically with this PR:prepareLoadScannow serializes through the copy-basedmarshalLoadSourceParamchannel for INLINE and INFILE alike; theScanType != INLINEfile-only guard is gone, and the old in-placeclearing of
Tail.ColumnList/Tail.Assignmentsbefore serialization isreplaced by the copy-based stripping, so the retained PREPARE AST keeps
its column list and assignment trees for replans.
TestPrepareLoadScanPrescanAndFailureexpectation thatTail.ColumnListis cleared after the scan was updated to the retainedAST contract (
require.Len(..., 1); cleared-transport invariant isinstead asserted by deserializing
Createsql), since the clearing iswhat this PR removes by design.
issue_31232_replan_source_param_test.gopasses the mocknationtable def to the widenedvalidateLoadSetAssignments.The stale pre-upgrade-bump thirdparties
usearchartifacts(
usearch-2.26.5-20261030shipped by upstream) were rebuilt locally viamake cgoso the rebased head compiles. Affected tests were re-run afterthe resolution: the focused selection (all issue UTs, downstream/upstream
prescan and
TestDependent*suites) and the unfiltered owning packagespkg/sql/planandpkg/sql/compileboth pass locally; BVT reruns areleft to repository CI.
CI fix (0cbe119): environment-neutral BVT show-create assertions
The pessimistic-BVT job failed on this PR's new
issue_31232_external_table_metadatacase because the recordedshow create tableresult pinned an exactINFILE{...}rendering whoseFILEPATHis environment-specific (the runner's absolute path differsfrom any local recording). Both assertions now use mo-tester
-- @regexdirectives (the repo's established convention, as intest/distributed/cases/dml/show/show_create_table.sql) to match thedeterministic parts and a wildcarded resource path, plus a negative
guard that rejects an emptied
FILEPATH. The recorded.resultlinesnow follow the
$resourcesconvention. The coverage job's failure wasdownstream of the same BVT failure (coverage merge blocked because the
pessimistic producer did not publish a profile); no Go code changed in
this follow-up commit.
CI fix (a3a865e): repair invalid mo-tester @regex directives
The PROXY multi-CN Compose BVT run (41942948439, job 126972490914)
aborted with
Invalid regex pattern 'INFILE\\{'FILEPATH'='',': Illegal repetition near index 7fromScriptParser.parseRegexFlag:mo-tester compiles the quoted
-- @regexcontent literally, and thedouble-backslash escapes over-escaped (
\\{never compiled as a braceescape;
\\.would only match a literal backslash before the dot),crashing the runner at script-parse time before the suite could run.
The four affected directives in
issue_31232_external_table_metadata.sqlnow use repository-standardcharacter-class escaping (
[{],[.]). All twelve directives wereverified to compile under
java.util.regexand hold against therecorded
SHOW CREATEoutput (include=true found, include=false notfound); SQL statements and expected results are unchanged.