StructField¶
StructField is a named field of a StructType.
Creating Instance¶
StructField takes the following to be created:
- Field Name
- DataType
-
nullableflag (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:
StructTypeis requested to toDDL- ShowCreateTableCommand,
ShowCreateTableAsSerdeCommandlogical commands are executed
toDDL gives a text in the format:
[quoted name] [dataType][optional comment]
toDDL is used when:
StructTypeis requested to convert itself to DDL format- ShowCreateTableCommand logical command is executed
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:
CatalogV2Utilis requested to applySchemaChangesAlterTableChangeColumnCommandlogical 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:
CatalogV2Utilis requested to applySchemaChanges and encodeDefaultValueAlterTableChangeColumnCommandlogical command is executed (to addCurrentDefaultValue)
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:
CatalogV2Utilis requested to encodeDefaultValue