Yaoxuan Wu created FLINK-41756:
----------------------------------
Summary: PyFlink collect() fails with "ValueError: malformed node
or string" for FLOAT NaN / Infinity values
Key: FLINK-41756
URL: https://issues.apache.org/jira/browse/FLINK-41756
Project: Flink
Issue Type: Bug
Components: API / Python
Affects Versions: 2.3.0
Reporter: Yaoxuan Wu
PyFlink {{collect()}} fails with {{ValueError: malformed node or string}} when
a FLOAT column holds NaN or Infinity. DOUBLE values and {{to_pandas()}} are
fine; only the row-by-row conversion of FLOAT fails.
{code:python}
from pyflink.table import EnvironmentSettings, TableEnvironment
t = TableEnvironment.create(EnvironmentSettings.in_batch_mode())
q = "SELECT CAST(s AS {}) FROM (VALUES ('NaN'), ('Infinity'), ('1.5')) AS v(s)"
print([tuple(r) for r in t.execute_sql(q.format('DOUBLE')).collect()]) #
[(nan,), (inf,), (1.5,)]
print(t.sql_query(q.format('FLOAT')).to_pandas().iloc[:, 0].tolist()) #
[nan, inf, 1.5]
print([tuple(r) for r in t.execute_sql(q.format('FLOAT')).collect()])
# expected: [(nan,), (inf,), (1.5,)]
# actual: ValueError: malformed node or string on line 1: <ast.Name object at
...>
{code}
{noformat}
File ".../pyflink/table/utils.py", line 143, in
pickled_bytes_to_python_converter
return field_type.from_sql_type(ast.literal_eval(data))
...
ValueError: malformed node or string on line 1: <ast.Name object at 0x...>
{noformat}
* Same for {{-Infinity}}, and for a FLOAT NaN created with {{from_elements}} or
the Table API {{cast(DataTypes.FLOAT())}}.
* The DataStream path fails the same way
({{t_env.to_data_stream(table).execute_and_collect()}} on a FLOAT column).
* Reproduces on 2.0.1, 2.2.1, 2.3.0 and master (2.4-SNAPSHOT, 2f01434,
2026-11-19).
Cause: the Python side converts a FLOAT value by parsing its string form with
{{ast.literal_eval}}, which accepts number literals but not the names {{NaN}} /
{{Infinity}}:
* {{pyflink/table/utils.py}}, {{pickled_bytes_to_python_converter}}: {{elif
isinstance(field_type, FloatType): return
field_type.from_sql_type(ast.literal_eval(data))}}
* {{pyflink/datastream/utils.py}}, {{pickled_bytes_to_python_obj}}: {{elif
type_info == Types.FLOAT(): return
type_info.from_internal_type(ast.literal_eval(data))}}
A possible fix: use {{float(data)}}, which accepts {{NaN}}, {{Infinity}} and
{{-Infinity}}.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)