Gabriel39 opened a new pull request, #71397:
URL: https://github.com/apache/doris/pull/71397

   ### Background
   
   Arrow, Parquet, ORC and Iceberg represent DATE values as proleptic Gregorian 
days since 1970. Doris stores DATE using MySQL day numbers, whose year zero 
omits the Gregorian leap day. File readers also use statistics to avoid 
decoding rows.
   
   ### What problem does this PR solve?
   
   Issue Number: close #67366
   Related PR: #68649 (merged source change, adapted to the current readers)
   PR Type: Bugfix
   
   Problem Summary:
   
   Exporting `0000-01-01` encoded day `-719527` instead of `-719528`, and 
importing Gregorian DATE values could shift January and February of year zero. 
A shared conversion now covers Arrow, Parquet, ORC and Iceberg DATE transforms. 
The port also makes metadata pruning and COUNT preserve invalid-DATE conversion 
behavior; most changed lines are tests and fixtures.
   
   ### Details
   
   - **Change map:** Engine code +314/-48; tests and fixtures +1732/-7; 
generated regression output +48/-34. The 442 lines under `tools/` comprise a 
162-line migration utility, 179 lines of tests and a 101-line guide.
   
   | Part | Purpose and approximate size |
   | --- | --- |
   | Calendar conversion | About 110 engine lines establish shared Gregorian 
boundaries and use them for DATE serialization and Iceberg day/bucket 
transforms. |
   | Metadata paths | About 250 engine lines prevent ORC SARG, zone maps and 
Parquet/ORC COUNT from hiding unrepresentable DATE values. |
   | Compatibility utility | Explicit offline migration for files confirmed to 
use the former Doris encoding; no heuristic detection. |
   
   - **Frequency:** Always for DATE values in `0000-01-01` through 
`0000-02-28`; other dates retain their ordinal.
   - **Root cause:** Directly subtracting or adding the Unix epoch MySQL day 
number ignores the missing year-zero leap day. Metadata shortcuts could also 
bypass conversion errors or conversion-generated NULLs.
   - **Why existing tests missed it:** Existing DATE serde and 
partition-transform tests lacked this calendar boundary. The HDFS ORC suite 
expected a permissive result for unrepresentable dates; its expectations now 
require the conversion error. Existing Flight and outfile coverage did not 
compare year-zero DATE wire values and cross-format round trips.
   - **Fix:** Centralize the calendar mapping and invalid-range checks, then 
require safe DATE statistics before taking metadata shortcuts. Unsafe ORC 
stripe ranges retain row decoding while safe ranges keep their SARG and 
timezone grouping.
   - **Other paths and branches:** Covers active FileScannerV2 DATE paths, 
including nested projections, Arrow date32/date64 and Iceberg DATE partitions. 
DATETIME is unchanged. This forwards the merged 4.2 work through master's 
reader architecture; older release branches were not validated for backporting.
   - **Behavior change:** Unrepresentable Gregorian dates, including 
`0000-02-29`, raise conversion errors in strict mode and become NULL where 
non-strict nullable conversion permits it. Files written with the former 
encoding require provenance-based migration; upgrading cannot distinguish their 
ambiguous ordinals.
   
   ### Testing
   
   Locally, 372 focused BE tests passed, including exhaustive 
representable-date comparison against cctz. Eleven new serde tests ran on the 
baseline and ten failed before the fix. An old-writer footer COUNT test also 
failed before the additional statistics-trust fix and passed afterward.
   
   Ten migration tests passed, covering nested values, NULLs, file round trips, 
failures and competing output publication. Actual SQL suites passed for Flight 
DATE/scalar-array results, Parquet/ORC outfile round trips, HDFS ORC group 6 
and Iceberg year-zero cross-reading and partition predicates with Spark.
   
   ### Notes for Reviewers
   
   The current ORC reader uses exclusive stripe endpoints and SDK-owned 
borrowed SARG evaluators; the adaptation preserves both lifetimes. Current 
master always uses FileScannerV2, so the deprecated scanner switch is not a 
legacy-file recovery path. The migration guide documents this and the 
requirement to rewrite Iceberg metadata through its writer.
   
   ### Release note
   
   Year-zero DATE values use correct Gregorian encoding in Arrow, Parquet, ORC 
and Iceberg partitions. Invalid external DATE values no longer bypass 
conversion through metadata shortcuts. Confirmed legacy Doris files need 
explicit migration before using the corrected reader.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: Yes; the migration guide is included, and 
the external DATE compatibility note should be reflected in the Doris website 
documentation when this ships.
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   - Tool: Codex, GPT-6
   - Generated: Forward-port adaptations, additional fixes and tests, migration 
guide and this description.
   - Human review: not stated
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to