This is an automated email from the ASF dual-hosted git repository.
dianfu pushed a commit to branch release-1.20
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/release-1.20 by this push:
new 029a14f1518 [FLINK-40236][python] Fix _infer_type inferring array
element type with a leading None (#28819)
029a14f1518 is described below
commit 029a14f151850ca46bb225b9e8d6b3cb151b9436
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 99e6676d687..88103b31dc4 100644
--- a/flink-python/pyflink/table/types.py
+++ b/flink-python/pyflink/table/types.py
@@ -1489,7 +1489,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):