This is an automated email from the ASF dual-hosted git repository.
dianfu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/master by this push:
new ea801695739 [FLINK-40236][python] Fix _infer_type inferring array
element type with a leading None (#28819)
ea801695739 is described below
commit ea801695739a4238cf2edfec1ff855100cb1e58b
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 f8124ba5e8c..9c7a47556cc 100644
--- a/flink-python/pyflink/table/tests/test_types.py
+++ b/flink-python/pyflink/table/tests/test_types.py
@@ -221,6 +221,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 964097f25e2..408dddfa6f7 100644
--- a/flink-python/pyflink/table/types.py
+++ b/flink-python/pyflink/table/types.py
@@ -1500,7 +1500,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):