Ramin Gharib created FLINK-38181:
------------------------------------
Summary: 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
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)