MaxGekk commented on code in PR #44644:
URL: https://github.com/apache/spark/pull/44644#discussion_r1448536657


##########
sql/api/src/main/scala/org/apache/spark/sql/types/StructField.scala:
##########
@@ -148,6 +148,24 @@ case class StructField(
     .map(" COMMENT '" + _ + "'")
     .getOrElse("")
 
+  /**
+   * Returns a string containing a DDL statement for data type. It handles a 
special
+   * case for StructType in order to capture `NOT NULL` field qualifier as 
well as field comment.
+   * This method is called recursively for nested struct(s).
+   */
+  private def getDataTypeDDL(dataType: DataType): String = {
+    dataType match {
+      case s: StructType =>
+        val fieldsDDL = s.fields.map { f =>
+          val nullString = if (f.nullable) "" else " NOT NULL"
+          s"${QuotingUtils.quoteIfNeeded(f.name)}: " +
+          s"${getDataTypeDDL(f.dataType)}$nullString${f.getDDLComment}"
+        }
+        s"STRUCT<${fieldsDDL.mkString(", ")}>"

Review Comment:
   Can't we incapsulate the logic inside of the method `StructType.sql()`?



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