Skip to content


StructField is a named field of a StructType.

Creating Instance

StructField takes the following to be created:

  • Field Name
  • DataType
  • nullable flag (default: true)
  • Metadata (default: Metadata.empty)

Converting to DDL Format

toDDL: String

toDDL uses the sql format of the DataType and the comment for conversion:

[name] [sql][comment]

toDDL is used when:

toDDL gives a text in the format:

[quoted name] [dataType][optional comment]

toDDL is used when:


getComment(): Option[String]

getComment is the value of the comment key in the Metadata (if defined).

DDL Comment

getDDLComment: String



import org.apache.spark.sql.types.{LongType, StructField}
val f = StructField(
    name = "id",
    dataType = LongType,
    nullable = false)
  .withComment("this is a comment")
scala> println(f)
scala> println(f.toDDL)
`id` BIGINT COMMENT 'this is a comment'

Last update: 2021-05-30