HyukjinKwon commented on code in PR #43572:
URL: https://github.com/apache/spark/pull/43572#discussion_r1375409233
##########
python/pyspark/sql/types.py:
##########
@@ -1216,6 +1216,45 @@ def fieldNames(self) -> List[str]:
"""
return list(self.names)
+ def treeString(self, maxDepth: Optional[int] = None) -> str:
+ """Return tree representation of the schema
+
+ .. versionadded:: 4.0.0
+
+ Parameters
+ ----------
+ maxDepth : int, optional, default None
+ Depth of the schema for nested schemas.
+
+ Examples
+ --------
+ >>> from pyspark.sql.types import *
+ >>> s = StructType(
+ ... [StructField("level1", StructType([StructField("f1", StringType(),
True)]), True)]
+ ... )
+
+ >>> s.treeString()
+ 'root\\n |-- level1: struct (nullable = true)\\n | |-- f1: string
(nullable = true)\\n'
+ >>> print(s.treeString())
+ root
+ |-- level1: struct (nullable = true)
+ | |-- f1: string (nullable = true)
+
+ >>> print(s.treeString(1))
+ root
+ |-- level1: struct (nullable = true)
+ """
+ from pyspark.sql import SparkSession
+
+ # Intentionally uses SparkSession so one implementation can be shared
with/without
+ # Spark Connect.
Review Comment:
connect DataFrame doesn't have `_tree_string` and access to JVM so it would
fail. We should add a test at `test_dataframe` as an example.
--
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]