khalidmammadov opened a new pull request, #43572:
URL: https://github.com/apache/spark/pull/43572

   ### What changes were proposed in this pull request?
   This PR adds missing parity method StructType.treeString() to Python API. 
   
   Usage examples:
   
   **PySpark**
   ```
   root@4691452b5bbd:/home/spark# bin/pyspark                    
   Python 3.9.5 (default, Nov 23 2021, 15:27:38) 
   ..... 
   >>> 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'
   >>> s.treeString(9)
   'root\n |-- level1: struct (nullable = true)\n |    |-- f1: string (nullable 
= true)\n'
   >>> s.treeString(-1)
   'root\n |-- level1: struct (nullable = true)\n |    |-- f1: string (nullable 
= true)\n'
   >>> s.treeString(1)
   'root\n |-- level1: struct (nullable = true)\n'
   >>> print(s.treeString(1))
   root
    |-- level1: struct (nullable = true)
   ```
   
   
   **Connect**
   ```
   root@4691452b5bbd:/home/spark# bin/pyspark --remote "local[*]"
   Python 3.9.5 (default, Nov 23 2021, 15:27:38) 
   ......
   >>> 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'
   >>> s.treeString(1)
   'root\n |-- level1: struct (nullable = true)\n'
   >>> s.treeString(0)
   'root\n |-- level1: struct (nullable = true)\n |    |-- f1: string (nullable 
= true)\n'
   >>> s.treeString(6)
   'root\n |-- level1: struct (nullable = true)\n |    |-- f1: string (nullable 
= true)\n'
   >>> s.treeString(-1)
   'root\n |-- level1: struct (nullable = true)\n |    |-- f1: string (nullable 
= true)\n'
   ```
   
   ### Why are the changes needed?
   To be compatible with Scala and allow users to access to the output of 
commonly used df.printSchema() without printing it out.
   
   ### Does this PR introduce _any_ user-facing change?
   Yes, a new Python method
   
   
   ### How was this patch tested?
   Added PySpark & Spark Connect test.
   
   
   ### 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]

Reply via email to