Skip to content

fix: backport load data and parquet compatibility - #24332

Merged
mergify[bot] merged 1 commit into
matrixorigin:3.0-devfrom
LeftHandCold:fix/issue24188-load-parquet-compat-3dev
May 12, 2026
Merged

mergify[bot] merged 1 commit into
matrixorigin:3.0-devfrom
LeftHandCold:fix/issue24188-load-parquet-compat-3dev

Conversation

@LeftHandCold

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

What this PR does / why we need it:

Backports and adapts the missing user-visible LOAD DATA / parquet compatibility fixes from main to 3.0-dev:

  • supports LOAD DATA TIMESTAMP parsing with the session timezone coverage
  • updates parquet-go and parquet mapping for basic/logical parquet types
  • supports parquet binary DECIMAL loading, including FixedLenByteArray, with source-to-target scale rescaling and target precision validation
  • treats AUTO_INCREMENT zero values consistently with MySQL sql_mode / NO_AUTO_VALUE_ON_ZERO in ingestion paths
  • supports JSON -> JSON cast so LOAD DATA into JSON columns does not fail with unsupported cast
  • updates related BVT coverage for load_data, auto_increment, fulltext, and snapshot cases

Validation:

  • go test ./pkg/sql/colexec/external -run 'Test(ReadFileOffsetCompressedUnsafe|_getColData_Timestamp|parquet|Parquet)' -count=1
  • go test ./pkg/sql/colexec/preinsert -run 'Test(ShouldConvertZeroToNullSkipOnUpdate|ShouldTreatZeroAsAutoIncrFallback|PreInsert)' -count=1
  • go test ./pkg/sql/plan/function -run 'TestCastJsonToJson|TestCastJson' -count=1
  • go test ./pkg/frontend -run 'TestGetSqlModeNoAutoValueOnZero|TestEnableRemapHint' -count=1

Copilot AI review requested due to automatic review settings May 11, 2026 03:53
@LeftHandCold
LeftHandCold requested a review from a user May 11, 2026 03:53
@qodo-code-review

Copy link
Copy Markdown
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

@CLAassistant

CLAassistant commented May 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR backports a set of user-visible ingestion compatibility fixes from main to 3.0-dev, focusing on LOAD DATA semantics (timezone-aware TIMESTAMP parsing, JSON casts, AUTO_INCREMENT zero handling) and improved Parquet type/DECIMAL support, along with expanded unit/BVT coverage.

Changes:

  • Extend Parquet scanning/type mapping (including logical types and DECIMAL loading/rescaling) and bump parquet-go.
  • Make ingestion AUTO_INCREMENT 0 handling respect sql_mode / NO_AUTO_VALUE_ON_ZERO, and update distributed snapshot/load_data fixtures accordingly.
  • Add/expand unit tests for Parquet, sql_mode caching, JSON→JSON cast, and LOAD DATA TIMESTAMP timezone behavior.

Reviewed changes

Copilot reviewed 30 out of 32 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/sql/colexec/external/parquet.go Parquet mapper/loader changes (logical types, DECIMAL handling, dictionary support, scan behavior).
pkg/sql/colexec/external/parquet_test.go Expanded unit coverage for Parquet mapping/dictionary/DECIMAL behaviors.
pkg/sql/colexec/external/external_timestamp_timezone_test.go Tests for session-timezone-aware TIMESTAMP parsing in LOAD DATA paths.
pkg/sql/colexec/preinsert/preinsert.go AUTO_INCREMENT zero handling updated to follow sql_mode semantics.
pkg/sql/colexec/preinsert/preinsert_test.go Unit tests covering the new AUTO_INCREMENT/sql_mode behavior.
pkg/sql/plan/function/func_cast.go Adds JSON→JSON cast support to avoid LOAD DATA failures into JSON columns.
pkg/sql/plan/function/func_cast_test.go Tests for JSON casting behavior (including JSON→JSON).
pkg/frontend/session.go Session cache/init for sql_mode NO_AUTO_VALUE_ON_ZERO parsing behavior.
pkg/frontend/session_sql_mode_test.go Unit tests validating sql_mode NO_AUTO_VALUE_ON_ZERO parsing and caching.
pkg/container/types/date.go Adds helper for converting “days from unix epoch” into Date (used by Parquet logical DATE mapping).
go.mod Bumps github.com/parquet-go/parquet-go dependency (and related module adjustments).
go.sum Corresponding dependency checksum updates.
test/distributed/cases/snapshot/sys_restore_to_nonsys_account.sql Sets/restores sql_mode to include NO_AUTO_VALUE_ON_ZERO around AUTO_INCREMENT inserts.
test/distributed/cases/snapshot/sys_restore_to_nonsys_account.result Expected output updated for sql_mode statements.
test/distributed/cases/snapshot/sys_restore_to_newnonsys_account.sql Same sql_mode scoping adjustment for AUTO_INCREMENT inserts.
test/distributed/cases/snapshot/sys_restore_to_newnonsys_account.result Expected output updated for sql_mode statements.
test/distributed/cases/snapshot/snapshot_restore_to_table_partition.sql Same sql_mode scoping adjustment for AUTO_INCREMENT inserts.
test/distributed/cases/snapshot/snapshot_restore_to_table_partition.result Regenerated expected output (now populated).
test/distributed/cases/snapshot/restore_fk_table.sql Same sql_mode scoping adjustment; fixes a trailing un-numbered line in fixture.
test/distributed/cases/snapshot/restore_fk_table.result Expected output updated for sql_mode statements.
test/distributed/cases/snapshot/cluster_level_snapshot_restore_to_nonsys_account.sql Same sql_mode scoping adjustment; fixes a trailing un-numbered line in fixture.
test/distributed/cases/snapshot/cluster_level_snapshot_restore_to_nonsys_account.result Expected output updated for sql_mode statements.
test/distributed/cases/load_data/load_data.sql Fixture updates to align LOAD DATA behavior with sql_mode/AUTO_INCREMENT semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/sql/colexec/external/parquet.go Resolved
Comment thread pkg/sql/colexec/preinsert/preinsert.go Resolved
@LeftHandCold
LeftHandCold force-pushed the fix/issue24188-load-parquet-compat-3dev branch from 21a4941 to f04deec Compare May 12, 2026 03:37

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

Requesting changes — not on the backport content itself (which I agree is desirable and was already approved by three reviewers), but because the PR as-is cannot merge and the rebase will need a non-trivial judgment call that deserves another look before it lands.

Blocking

Merge conflicts with #24329 (Hive-partitioned Parquet), now merged into 3.0-dev at d8a036c:

CONFLICT (content): Merge conflict in pkg/sql/colexec/external/parquet.go
CONFLICT (content): Merge conflict in pkg/sql/colexec/external/parquet_test.go

Both collide in the part of scanParquetFile / newParquetHandler that this PR rewrites end-to-end for logical-type and DECIMAL support. The Hive PR added:

  • param.refreshPartitionValues() call before newParquetHandler
  • h.filepathColIndex / h.partitionColIndices / h.hasPhysicalCol fields
  • h.fillVirtualColumns(bat, param, proc) at the end of each batch
  • h.rowCountOnly completion logic that nils param.parqh and advances Fileparam.FileFin
  • isHivePartitionCol and findColumnIgnoreCase gating in prepare

None of those live in this PR's rewrite. After rebase, three things need to be preserved/re-integrated — not auto-resolved:

  1. scanParquetFile has to keep calling refreshPartitionValues + fillVirtualColumns + honoring rowCountOnly. Otherwise Hive external tables silently return empty partition columns / never finalize the last file.
  2. prepare() has to keep the isHivePartitionCol / ContainExternalHidenCol branches that skip physical-column lookup for virtual columns. Otherwise Hive BVT fails with "column not found" on partition columns.
  3. getMapper must keep findColumnIgnoreCase's ambiguity check that 24329 added. If the backport reintroduces a case-sensitive lookup, mixed-case Hive partition DDL regresses.

Could you rebase onto current 3.0-dev and push, so the final parquet.go/parquet_test.go shape can be reviewed as a whole? I don't want to pre-approve a file I haven't seen the merged version of.

Non-blocking nits I noticed while reviewing

  • pkg/frontend/session.go:581 adds atomic.StoreInt32(&ses.sqlModeNoAutoValueOnZero, -1) in NewSession, but 3.0-dev already resets this in InitSystemVariables at line 275. The new reset isn't wrong (belt-and-suspenders during session construction before sysvars init), but consider whether it's actually reachable before InitSystemVariables runs. If not, it can be dropped.
  • preinsert_test.go still sets preInsert.ctr.tblId = preInsert.TableDef.TblId at lines 502/561/610. ctr.tblId exists on 3.0-dev but isn't read by the refactored code path (which uses preInsert.autoIncrementTableID). These writes are dead. Not this PR's fault — inherited from 3.0-dev — but if you're touching the tests, removing them would reduce confusion.
  • Commit is a single squash titled "fix: backport load data and parquet compatibility". Given the scope (parquet mapper overhaul + AUTO_INCREMENT sql_mode + JSON→JSON cast + DATE helper + sysvar cache init), splitting into ~4 commits in the squash message (one per upstream PR being ported, with upstream PR numbers referenced) would make this much easier to bisect later. Not blocking — just a request for the final merge message.

What I'd approve

A rebased version that visibly preserves (1)–(3) under "Blocking" and whose BVT run includes both the load_data backport cases and the existing hive_partition_external_table.sql (24329's BVT). Happy to re-review quickly once it's pushed.

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

@Copilot I rebased PR #24332 onto current 3.0-dev after #24329 and pushed the final merged parquet.go/parquet_test.go shape at 11246d9.\n\nChecked the blocking items from this review:\n\n1. scanParquetFile keeps refreshPartitionValues(), fillVirtualColumns(), and rowCountOnly finalization.\n2. prepare() keeps isHivePartitionCol and ContainExternalHidenCol branches, and now still validates ColIndex before indexing.\n3. physical columns still use findColumnIgnoreCase(), including the ambiguity check.\n\nI also adjusted the getData finish/offset unit test to match #24329/base behavior after the rebase.\n\nValidation run locally:\nsh\ngo test ./pkg/sql/colexec/external -run 'TestHive|TestParquet|Test_getMapper|Test_getData|Test_parquet' -count=1\ngo test ./pkg/sql/compile -run 'TestCompileExternScanHiveFileFanout' -count=1\ngo test ./pkg/sql/plan -run 'Test(ParseHiveOptionKV|InitInfileParam_HiveLegacyOption|InitS3Param_HiveLegacyOption|ParseHiveOptionsFromRawOptions_AllPaths|StripHiveOptionKeys|ValidateAndSetHivePartitionOptions_)' -count=1\ngo test ./pkg/sql/colexec/preinsert ./pkg/sql/plan/function ./pkg/frontend ./pkg/container/types -count=1\n\n\nThe PR is now mergeable; there were no inline review threads on this review to resolve.

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

LGTM on the rebased version (f04deec).

Verified the three integration points I flagged as must-preserve after the #24329 merge into 3.0-dev:

  1. scanParquetFile still calls refreshPartitionValues before newParquetHandler, still calls fillVirtualColumns when partition/filepath cols are projected, and still honors rowCountOnly to nil param.parqh + advance Fileparam.FileFin (parquet.go:43-85).
  2. prepare keeps the isHivePartitionCol → partitionColIndices branch and the ContainExternalHidenCol → filepathColIndex branch before physical-column lookup, and only sets hasPhysicalCol for real parquet-backed columns (parquet.go:160-218).
  3. findColumnIgnoreCase still ambiguity-checks multiple case-insensitive matches (parquet.go:131-157).

The production delta vs. 3.0-dev is now ~500 lines in parquet.go (down from ~800 pre-rebase) and reads surgically: uint8/uint16/uint32 widening mappers, bounds-check on attr.ColIndex in prepare, NYI message tweak for nested types, plus the DECIMAL/DATE/TIMESTAMP mapper overhauls from #22714 that were the point of this backport.

Retracting one earlier nit: I was wrong about NewSession:581 atomic.StoreInt32(&ses.sqlModeNoAutoValueOnZero, -1) being redundant with InitSystemVariables:275. Go zero-init would leave the field at 0, which GetSqlModeNoAutoValueOnZero treats as "cached: NO_AUTO_VALUE_ON_ZERO absent" rather than "uncached". The -1 at NewSession time is load-bearing.

Remaining dead preInsert.ctr.tblId = … writes at preinsert_test.go:502,561,610 — inherited from 3.0-dev, not this PR's regression; leave for a separate cleanup.

CI is rerunning on the rebased head; merge after it clears.

@mergify

mergify Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-12 04:53 UTC · Rule: release-3.0
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-05-12 04:53 UTC · at 11246d9c0688218e178aa465befced31b84e7adc · squash

This pull request spent 20 seconds in the queue, including 3 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI (3.0) / Coverage
    • check-neutral = Matrixone Utils CI (3.0) / Coverage
    • check-skipped = Matrixone Utils CI (3.0) / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)

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 kind/test-ci size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants