SEPURI-SAI-KRISHNA commented on issue #12612:
URL: https://github.com/apache/seatunnel/issues/12612#issuecomment-6412043157

   Both asks, @SEZ9, and one thing I found while doing the second.
   
   **1. Already in, verbatim.** The entry has carried this since it was 
written, so nothing changed for it:
   
   > **The reachable route is `COALESCE` and `IFNULL`, not `CAST`** ... A 
`DECIMAL` or `DOUBLE` reaches the target through `COALESCE` and `IFNULL`, whose 
result type is inferred from the first non-null argument rather than the 
widest, so `COALESCE(bigint_col, decimal_col)` targets `BIGINT` and narrowed 
the decimal silently.
   
   The ZH entry says the same, so a release-notes reader is told where the new 
failure can appear.
   
   **2. Was not in, now added.** You are right, and I should not have counted 
this as done. The Migration Guide only had the workaround in prose and never 
gave the line. Both languages now carry it:
   
   > To keep the widest type rather than the type of the first argument, write 
the cast yourself: `COALESCE(CAST(int_col AS BIGINT), bigint_col)`.
   
   I ran it before documenting it, with `int_col` = 7 and `bigint_col` = 9:
   
   | query | declared result type |
   | --- | --- |
   | `COALESCE(int_col, bigint_col)` | `INT` |
   | `COALESCE(CAST(int_col AS BIGINT), bigint_col)` | `BIGINT` |
   | `IFNULL(CAST(int_col AS BIGINT), bigint_col)` | `BIGINT` |
   
   Row 1 is the "first argument wins" contract measured rather than argued.
   
   **3. That probe turned up a documentation bug, and I have fixed it here.** 
`sql-functions.md` declared:
   
   ```
   IFNULL(aValue, bValue) -> type(common of args)
   ```
   
   which contradicts the sentence directly below it in the same section, 
"automatically converted to the type of the first argument", and contradicts 
the behaviour. Measured: `IFNULL(int_col, bigint_col)` is `INT`, 
`IFNULL(bigint_col, int_col)` is `BIGINT`, `IFNULL(int_col, str_col)` is `INT`. 
It is first argument, exactly like `COALESCE`. The signature now reads `type(of 
first non-null arg)` in EN and ZH.
   
   This matters for exactly the reason behind your two asks: a user reading 
"common of args" concludes the widest type is chosen and that the new `BIGINT` 
failure cannot reach them. I also put the workaround in the `COALESCE` and 
`IFNULL` sections themselves, since the PR's existing paragraph sits under 
`CAST` and that is not where someone looks it up.
   
   All of it is documentation only, EN and ZH, no production or test change, so 
the behaviour you reviewed is untouched. Say the word if you would rather the 
`IFNULL` signature correction went as its own PR.
   


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