snuyanzin commented on code in PR #28758:
URL: https://github.com/apache/flink/pull/28758#discussion_r3613589952
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CastFunctionITCase.java:
##########
@@ -151,35 +151,47 @@ private static List<TestSetSpec> variantCasts() {
"CAST(PARSE_JSON('42') AS INT)",
42,
INT().notNull())
- // Integer overflow wraps around (Java narrowing),
like a regular numeric
- // cast.
+ // Spark-style overflow: an integer value outside the
target range fails
+ // CAST and returns NULL for TRY_CAST, instead of
wrapping around.
+ .testTableApiRuntimeError(
+ call("PARSE_JSON", "40000").cast(SMALLINT()),
"overflowed")
+ .testSqlRuntimeError("CAST(PARSE_JSON('40000') AS
SMALLINT)", "overflowed")
.testResult(
- call("PARSE_JSON", "40000").cast(SMALLINT()),
- "CAST(PARSE_JSON('40000') AS SMALLINT)",
- (short) -25536,
- SMALLINT().notNull())
- .testResult(
- call("PARSE_JSON", "128").cast(TINYINT()),
- "CAST(PARSE_JSON('128') AS TINYINT)",
- (byte) -128,
- TINYINT().notNull())
+ call("PARSE_JSON",
"40000").tryCast(SMALLINT()),
+ "TRY_CAST(PARSE_JSON('40000') AS SMALLINT)",
+ null,
+ SMALLINT())
+ .testTableApiRuntimeError(
+ call("PARSE_JSON", "128").cast(TINYINT()),
"overflowed")
Review Comment:
yes, however it does not answer why we expect `NULL` after that
--
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]