[
https://issues.apache.org/jira/browse/FLINK-38181?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Timo Walther closed FLINK-38181.
--------------------------------
Fix Version/s: 2.2.0
Release Note: Casting to TIME type now consideres the correct precision
(0-3). Casting incorrect strings to time (e.g. where the hour component is
higher than 24) leads to a runtime exception now. Casting between BINARY and
VARBINARY should now correctly consider the target length.
Resolution: Fixed
Fixed in master: eef14cb8781ae06e53dedcd6848b1707b2081a17
> Code generation fails for ROW() with CAST to SMALLINT/TINYINT when input is
> non-literal
> ---------------------------------------------------------------------------------------
>
> Key: FLINK-38181
> URL: https://issues.apache.org/jira/browse/FLINK-38181
> Project: Flink
> Issue Type: Bug
> Components: Table SQL / Planner
> Reporter: Ramin Gharib
> Assignee: Ramin Gharib
> Priority: Major
> Labels: pull-request-available
> Fix For: 2.2.0
>
>
> h3. Summary
> When using the ROW() function with CAST() to SMALLINT or TINYINT types on
> non-literal input expressions, code generation fails with a compilation
> error. The generated Java code produces incorrectly typed default values that
> don't match method signatures.
> h3. Description
> *Problem:*
> The primitiveDefaultValue() method in CodeGenUtils.scala returns untyped
> integer literals ("-1") for both TINYINT and SMALLINT types. When these
> default values are used in generated code, they fail to compile because they
> don't match the expected parameter types for methods like
> BinaryRowWriter.writeShort(int, short).
> {*}Root Cause:
> {*}In CodeGenUtils.primitiveDefaultValue(), the method has:
> {code:java}
> case TINYINT | SMALLINT | INTEGER | DATE | TIME_WITHOUT_TIME_ZONE |
> INTERVAL_YEAR_MONTH => "-1" {code}
> This generates Java code like:
> {code:java}
> writer.writeShort(0, -1); // Compilation error: -1 is int, not short {code}
> *Expected Behavior:*
> The method should return properly typed literals:
> {code:java}
> TINYINT → "((byte) -1)"
> SMALLINT → "((short) -1)"{code}
> h3. Steps to Reproduce
> Execute the following SQL query:
> {code:java}
> SELECT ROW(CAST(SCORE AS SMALLINT)) FROM (VALUES (1), (2), (3)) AS T(SCORE)
> {code}
> Observe the compilation error during code generation:
> {code:java}
> Caused by: org.codehaus.commons.compiler.CompileException: Line 22, Column
> 20: No applicable constructor/method found for actual parameters "int, int";
> candidates are: "public void
> org.apache.flink.table.data.writer.BinaryRowWriter.writeShort(int, short)",
> "public abstract void
> org.apache.flink.table.data.writer.BinaryWriter.writeShort(int, short)" {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)