rionmonster opened a new pull request, #30245:
URL: https://github.com/apache/flink/pull/30245

   ## What is the purpose of the change
   
   In batch mode, `RANK`, `DENSE_RANK` and `PERCENT_RANK` over a 
`TIMESTAMP_LTZ` order key fail at planning with `Unsupported type: 
TIMESTAMP_LTZ(3)`. A processing-time order key fails the same way, since 
`PROCTIME()` is a `TIMESTAMP_LTZ(3)` column in batch mode.
   
   `RankLikeAggFunctionBase#generateInitLiteral` initializes the last order key 
in the aggregate buffer with a literal that it picks from a list of types. 
`TIMESTAMP_LTZ` is not in the list. Neither are `BINARY`, `VARBINARY`, the 
interval types, `ARRAY` and `ROW`, which fail with the same error.
   
   The initial value is never compared: on the first row of a partition 
`sequence` is 0, so the row always starts a new rank, and afterwards the buffer 
holds the previous order key. This PR initializes the buffer with NULL of the 
order key type instead, which exists for every type.
   
   ## Brief change log
   
     - `RankLikeAggFunctionBase#generateInitLiteral` returns a NULL literal of 
the order key type instead of a literal from a list of supported types
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - `OverAggregateITCase#testRankByTimestampLtz`: `TIMESTAMP_LTZ` order keys 
of precision 0, 3, 6 and 9, with ties and a NULL key
     - `OverAggregateITCase#testRankByProctime`: `PROCTIME()` as the order key
     - `OverAggregateITCase#testRankByBytesAndIntervals`: `BYTES`, `INTERVAL 
SECOND` and `INTERVAL MONTH` order keys
     - `OverAggregateITCase#testRankByArrayAndRow`: `ARRAY<INT>` and `ROW<x 
INT, y INT>` order keys
     - `OverAggregateITCase#testRankByNotNullKey`: `NOT NULL` order keys 
(`INT`, `STRING`, `DECIMAL(20, 0)`, `TIMESTAMP_LTZ(9)`), because the buffer now 
starts with NULL for them too
   
   All five fail without the fix and pass with it:
   
   | Test | Without the fix | With the fix |
   |---|---|---|
   | `testRankByTimestampLtz` | `Unsupported type: TIMESTAMP_LTZ(0)` | passes |
   | `testRankByProctime` | `Unsupported type: TIMESTAMP_LTZ(3) NOT NULL 
*PROCTIME*` | passes |
   | `testRankByBytesAndIntervals` | `Unsupported type: BYTES` | passes |
   | `testRankByArrayAndRow` | `Unsupported type: ARRAY<INT> NOT NULL` | passes 
|
   | `testRankByNotNullKey` | `Unsupported type: TIMESTAMP_LTZ(9)` | passes |
   
   ## 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): no
     - 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
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   


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