panbingkun commented on code in PR #44665: URL: https://github.com/apache/spark/pull/44665#discussion_r1520791983
########## python/pyspark/sql/functions/builtin.py: ########## @@ -15534,19 +15532,7 @@ def to_csv(col: "ColumnOrName", options: Optional[Dict[str, str]] = None) -> Col | 2,Alice| +-------------+ - Example 2: Converting a complex StructType to a CSV string - - >>> from pyspark.sql import Row, functions as sf - >>> data = [(1, Row(age=2, name='Alice', scores=[100, 200, 300]))] - >>> df = spark.createDataFrame(data, ("key", "value")) - >>> df.select(sf.to_csv(df.value)).show(truncate=False) # doctest: +SKIP - +-----------------------+ - |to_csv(value) | - +-----------------------+ - |2,Alice,"[100,200,300]"| Review Comment: In `this case` of Python, it is because the data type is ArrayData (specifically implemented as `GenericArrayData`), This case just goes into the following logic: https://github.com/apache/spark/blob/09bdf2a9334f210ece4c23d0f3324f81113330d0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv/UnivocityGenerator.scala#L91-L93 https://github.com/apache/spark/blob/09bdf2a9334f210ece4c23d0f3324f81113330d0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/GenericArrayData.scala#L85 And it just so happens that `GenericArrayData` overrides the `toString` method, so it appears to display the result `correctly`, perhaps it's just a `coincidence`? -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org