dongjoon-hyun commented on a change in pull request #24098: [SPARK-27166][SQL] 
Improve `printSchema` to print up to the given level
URL: https://github.com/apache/spark/pull/24098#discussion_r369848240
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructType.scala
 ##########
 @@ -310,13 +310,19 @@ case class StructType(fields: Array[StructField]) 
extends DataType with Seq[Stru
   protected[sql] def toAttributes: Seq[AttributeReference] =
     map(f => AttributeReference(f.name, f.dataType, f.nullable, f.metadata)())
 
-  def treeString: String = {
+  def treeString: String = treeString(Int.MaxValue)
+
+  def treeString(level: Int): String = {
     val builder = new StringBuilder
     builder.append("root\n")
     val prefix = " |"
     fields.foreach(field => field.buildFormattedString(prefix, builder))
 
-    builder.toString()
+    if (level <= 0 || level == Int.MaxValue) {
+      builder.toString()
+    } else {
+      builder.toString().split("\n").filter(_.lastIndexOf("|--") < level * 5 + 
1).mkString("\n")
 
 Review comment:
   Got it. Let me think about that way.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to