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:
StructType
is requested to toDDL- ShowCreateTableCommand,
ShowCreateTableAsSerdeCommand
logical commands are executed
toDDL
gives a text in the format:
[quoted name] [dataType][optional comment]
toDDL
is used when:
StructType
is 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:
CatalogV2Util
is requested to applySchemaChangesAlterTableChangeColumnCommand
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:
CatalogV2Util
is requested to applySchemaChanges and encodeDefaultValueAlterTableChangeColumnCommand
logical 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:
CatalogV2Util
is requested to encodeDefaultValue