Anirban-Chand opened a new pull request, #60792: URL: https://github.com/apache/spark/pull/60792
### What changes were proposed in this pull request? This PR resolves [SPARK-62231](https://issues.apache.org/jira/browse/SPARK-62231) by updating `StructType.__init__` in `python/pyspark/sql/types.py` so that: - `self.names` and the `StructField` assertion are resolved from `self.fields` instead of the raw `fields` parameter. - When subclassed with custom `fields` property/attribute, `fields`, `names`, `_needConversion`, and `_needSerializeAnyField` all consistently route through the subclass's attributes. ### Why are the changes needed? In [SPARK-62231](https://issues.apache.org/jira/browse/SPARK-62231), `StructType.__init__` assigned `self.fields` and computed `self._needConversion` through `self` (respecting subclass attribute/property overrides), but `self.names` and the `StructField` assertion read directly from the `fields` parameter: - When initialized with `fields=None`, a subclass overriding `fields` ended up with `self.names = []` despite `self.fields` and `self._needConversion` being populated. - When initialized with arguments, `self.names` reflected the constructor argument rather than the subclass's `self.fields`. - If a subclass defined a `fields` property returning objects that are not `StructField`, `self.names` failed to resolve them through the subclass property. ### Does this PR introduce _any_ user-facing change? No. Standard `StructType` behavior is unchanged. Subclasses overriding `fields` now have consistent `names`, `fields`, and conversion attributes. ### How was this patch tested? Added `test_struct_type_subclass` in `python/pyspark/sql/tests/test_types.py`. ### Was this patch authored or co-authored using generative AI tooling? No -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
