1996fanrui opened a new pull request, #29775:
URL: https://github.com/apache/flink/pull/29775

   ## What is the purpose of the change
   
   Backport of #29689 
([FLINK-41280](https://issues.apache.org/jira/browse/FLINK-41280)) to 
release-1.20.
   
   A CAST of a TIMESTAMP before 1970 to DATE, TIME or a TIMESTAMP of lower 
precision rounded the epoch milliseconds toward zero, so the result moved 
toward 1970 (e.g. `1969-12-31 23:59:59.999` cast to DATE gave `1970-01-01`). 
This uses floor division instead.
   
   ## Difference from master
   
   On master the TIMESTAMP to TIME conversion is done in 
`DateTimeUtils.timestampWithoutLocalZoneToTime`, which the original fix changed 
to `Math.floorMod`. That method does not exist on release-1.20: the conversion 
is generated by `TimestampToTimeCastRule`, which still used `%`, so the master 
fix alone does not cover TIME on 1.20 and the new TIME test case fails. This PR 
therefore has two commits:
   
   1. The cherry-pick of 0196674 with the `timestampWithoutLocalZoneToTime` 
hunk dropped (it conflicted because the method is absent); the 
`TimestampToDateCastRule` and `zeroLastDigits` changes and the tests apply 
unchanged.
   2. An extra 1.20-only change that makes `TimestampToTimeCastRule` use 
`Math.floorMod` instead of `%`, mirroring what master does in 
`timestampWithoutLocalZoneToTime`.
   
   ## Brief change log
   
     - `TimestampToDateCastRule`: `Math.floorDiv` instead of `/` for TIMESTAMP 
to DATE
     - `DateTimeUtils.zeroLastDigits`: `Math.floorDiv` instead of `/`, used by 
`truncate()` for a TIMESTAMP/TIMESTAMP_LTZ precision of 3 or less
     - `TimestampToTimeCastRule` (1.20 only): `Math.floorMod` instead of `%` 
for TIMESTAMP to TIME
     - `CastFunctionITCase`: cases for a TIMESTAMP before 1970 cast to DATE, 
TIME and TIMESTAMP(0)
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - `CastFunctionITCase` (with the new pre-1970 cases for DATE, TIME and 
TIMESTAMP(0)) and `CastRulesTest` pass on this branch.
     - Without the `TimestampToTimeCastRule` change, the new TIME case in 
`CastFunctionITCase` fails (expected `23:59:59`, but was `00:00`), confirming 
the extra commit is needed on 1.20.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): yes 
(generated cast code; `Math.floorMod`/`floorDiv` replace `%`/`/`)
     - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? no
     - If yes, how is the feature documented? not applicable
   
   cc @raminqaf (author of the original fix), could you please review this 
backport, especially the extra `TimestampToTimeCastRule` change?
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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]

Reply via email to