Liu Liu created FLINK-40300:
-------------------------------
Summary: PyFlink Table API lit does not convert Python values to
the required Java literal types
Key: FLINK-40300
URL: https://issues.apache.org/jira/browse/FLINK-40300
Project: Flink
Issue Type: Bug
Components: API / Python
Affects Versions: 1.12.0
Reporter: Liu Liu
Fix For: 2.4.0
{{pyflink.table.expressions.lit(value, data_type)}} passes the Python value
directly to Java. Py4J converts Python values to general Java types (e.g.,
Python {{int}} to {{{}java.lang.Integer{}}}) while Flink requires the value to
match the declared data type’s conversion class exactly, such as
{{java.lang.Short}} for {{{}SMALLINT{}}}. No conversion is performed between
these representations.
For example:
{{{{from pyflink.table import DataTypes
from pyflink.table.expressions import lit
lit(1, DataTypes.SMALLINT(False))}}}}
This fails with:
{{org.apache.flink.table.api.ValidationException:
Data type 'SMALLINT NOT NULL' with conversion class 'java.lang.Short'
does not support a value literal of class 'java.lang.Integer'.}}
The issue affects at least {{{}TINYINT{}}}, {{{}SMALLINT{}}}, {{BIGINT}} for
32-bit values, {{{}FLOAT{}}}, {{{}DATE{}}}, {{{}TIME{}}}, {{{}TIMESTAMP{}}},
{{{}TIMESTAMP_LTZ{}}}, intervals, and some constructed types. It also affects
the DataFrame API because its {{lit}} method delegates to the Table API
implementation.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)