Yicong-Huang commented on code in PR #57911:
URL: https://github.com/apache/spark/pull/57911#discussion_r3819106567


##########
python/pyspark/sql/conversion.py:
##########
@@ -685,6 +685,27 @@ def convert_array(value: Any) -> Any:
                         assert isinstance(value, (list, array.array))
                         return list(value)
 
+            elif isinstance(dataType.elementType, (StringType, BinaryType)):
+                # Inline the scalar identity fast path so elements that are
+                # already the target Python type skip the per-element converter
+                # call entirely: `convert_string`/`convert_binary` return such
+                # elements unchanged. `str` and immutable `bytes` are the two
+                # element types whose converter is a no-op on a matching value.
+                # Any other element -- including `None` (whose nullability is
+                # enforced by `element_conv`) and values that need coercion 
(e.g.
+                # a bool to string) -- falls back to `element_conv`, reused
+                # unchanged.
+                fast_type = str if isinstance(dataType.elementType, 
StringType) else bytes

Review Comment:
   I actually tried handling `None` in the fast path, but it bypasses the 
`containsNull` check in `element_conv`. PyArrow silently accepts the null even 
when `containsNull=False`, so we’d violate the schema contract instead of 
raising a clear PySparkValueError. That’s why I left None to go through 
`element_con`



-- 
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]

Reply via email to