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'

Removing CURRENT_DEFAULT Metadata Attribute

clearCurrentDefaultValue(): StructField

clearCurrentDefaultValue removes (clears) CURRENT_DEFAULT column metadata attribute from this Metadata.


clearCurrentDefaultValue is used when:

  • CatalogV2Util is requested to applySchemaChanges
  • AlterTableChangeColumnCommand logical command is executed

Updating CURRENT_DEFAULT Metadata Attribute

withCurrentDefaultValue(
  value: String): StructField

withCurrentDefaultValue adds or updates CURRENT_DEFAULT column metadata attribute (of this Metadata) to the given value.


withCurrentDefaultValue is used when:

Updating EXISTS_DEFAULT Metadata Attribute

withExistenceDefaultValue(
  value: String): StructField

withExistenceDefaultValue adds or updates EXISTS_DEFAULT column metadata attribute (of this Metadata) to the given value.


withExistenceDefaultValue is used when: