Skip to content

StructField

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:

Comment

getComment(): Option[String]

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

DDL Comment

getDDLComment: String

getDDLComment...FIXME

Demo

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)
StructField(id,LongType,false)
scala> println(f.toDDL)
`id` BIGINT COMMENT 'this is a comment'