snuyanzin commented on code in PR #28758:
URL: https://github.com/apache/flink/pull/28758#discussion_r3613292046
##########
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:
why do we do this this way?
Better to have same way as regular cast
Then there is `SqlConformance#checkedArithmetic` which we can make use to
switch between different behavior
--
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]