This is an automated email from the ASF dual-hosted git repository.
dianfu pushed a commit to branch release-2.3
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/release-2.3 by this push:
new 7365c778d0d [FLINK-40236][python] Fix _infer_type inferring array
element type with a leading None (#28819)
7365c778d0d is described below
commit 7365c778d0d9f4781a1e5ad600e1369116eca1f4
Author: Nikolaus Schuetz <[email protected]>
AuthorDate: Mon Aug 3 02:06:33 2026 -0700
[FLINK-40236][python] Fix _infer_type inferring array element type with a
leading None (#28819)
_infer_type inferred a list's element type from obj[0] rather than the
first non-None element the loop scans for, so a leading None collapsed
the array element type to NULL. Infer from the scanned element v
instead, matching the dict branch above.
---
flink-python/pyflink/table/tests/test_types.py | 5 +++++
flink-python/pyflink/table/types.py | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/flink-python/pyflink/table/tests/test_types.py
b/flink-python/pyflink/table/tests/test_types.py
index d3bd37c6ffd..6a415e78114 100644
--- a/flink-python/pyflink/table/tests/test_types.py
+++ b/flink-python/pyflink/table/tests/test_types.py
@@ -209,6 +209,11 @@ class TypesTests(PyFlinkTestCase):
# third column is varchar
self.assertTrue(isinstance(schema.fields[2].data_type, VarCharType))
+ def test_infer_array_type_with_leading_none(self):
+ data_type = _infer_type([None, 1])
+ self.assertTrue(isinstance(data_type, ArrayType))
+ self.assertTrue(isinstance(data_type.element_type, BigIntType))
+
def test_infer_schema_not_enough_names(self):
schema = _infer_schema_from_data([["a", "b"]], ["col1"])
self.assertTrue(schema.names, ['col1', '_2'])
diff --git a/flink-python/pyflink/table/types.py
b/flink-python/pyflink/table/types.py
index b62b55af9e1..0182a3c3d69 100644
--- a/flink-python/pyflink/table/types.py
+++ b/flink-python/pyflink/table/types.py
@@ -1491,7 +1491,7 @@ def _infer_type(obj):
elif isinstance(obj, list):
for v in obj:
if v is not None:
- return ArrayType(_infer_type(obj[0]))
+ return ArrayType(_infer_type(v))
else:
return ArrayType(NullType())
elif isinstance(obj, array):