SEPURI-SAI-KRISHNA commented on PR #12605:
URL: https://github.com/apache/seatunnel/pull/12605#issuecomment-6036700503
Thanks for holding on F2. Checking the wording showed my note was wrong in
more places than the one you flagged, so I rewrote both pages and pushed.
I ran the expressions through `ZetaSQLEngine` rather than reading the
source, and measured:
- `CAST(5.7 AS INT)` does not give `5`. It fails with `Unsupported CAST FROM
DOUBLE AS type: INT`, from `CastFunction.getCastType` via
`ZetaSQLType.getExpressionType:194` during `typeMapping`, so a job fails at
startup, not on a row. Same for `CAST(bigint_col AS TINYINT)`.
- `BYTE` is not parseable as a CAST target: JSqlParser reports `Encountered
unexpected token: "BYTE"`.
- `TRY_CAST` does not rescue those: they are rejected before
`executeTryCastExpr` runs. It only converts row-time failures to `NULL`.
- Truncation towards zero is real, but only via `COALESCE`/`IFNULL`, where
the target type is inferred: `COALESCE(int_col, double_col)` on `5.7` gives `5`.
- The error type in my original note was correct after all:
`project():341-342` wraps every expression failure via
`TransformCommonError.sqlExpressionError`, a `TransformException`, with
`NumberFormatException` only as the cause.
The CAST note now reads:
```text
NOTE:
Casting to `INT` | `INTEGER` throws a `TransformException` when the source
value is outside the
target's range, for example `CAST(3000000000 AS INT)`. `TINYINT` and
`SMALLINT` behave the same way
for a string source, such as `CAST('300' AS TINYINT)`. Use `TRY_CAST` to get
`NULL` instead of an
error.
A narrowing or floating-point source is rejected earlier, while the
statement is prepared rather
than while a row is read: `CAST(double_col AS INT)` and `CAST(bigint_col AS
TINYINT)` both fail with
`Unsupported CAST FROM ... AS type: ...`, and `TRY_CAST` does not turn those
into `NULL`. A
fractional value reaches an integral target only through `COALESCE` or
`IFNULL`, where the target
type is inferred rather than written, and there it is truncated towards
zero: when `int_col` is
`NULL`, `COALESCE(int_col, double_col)` on `5.7` gives `5`.
```
On your conditions: (a) scoped to `INT` | `INTEGER` for a numeric source
plus `TINYINT`/`SMALLINT` for a string source, which is what actually rejects,
`BIGINT` left out per #12612; (b) current behaviour, no narration.
I also scoped the `incompatible-changes.md` fractional bullet to
`COALESCE`/`IFNULL`, which as written implied `CAST` truncates a float. Line
1165 also lists `BYTE`, which CAST cannot parse; that predates this PR, so I
would file it separately.
--
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]