StructField — Single Field in StructType
StructField describes a single field in a StructType with the following:
A comment is part of metadata under comment key and is used to build a Hive column or when describing a table.
|
1 2 3 4 5 6 7 8 9 |
scala> schemaTyped("a").getComment res0: Option[String] = None scala> schemaTyped("a").withComment("this is a comment").getComment res1: Option[String] = Some(this is a comment) |
As of Spark 2.4.0, StructField can be converted to DDL format using toDDL method.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Example: Using StructField.toDDL import org.apache.spark.sql.types.MetadataBuilder val metadata = new MetadataBuilder() .putString("comment", "this is a comment") .build import org.apache.spark.sql.types.{LongType, StructField} val f = new StructField(name = "id", dataType = LongType, nullable = false, metadata) scala> println(f.toDDL) `id` BIGINT COMMENT 'this is a comment' |
Converting to DDL Format — toDDL Method
|
1 2 3 4 5 |
toDDL: String |
toDDL gives a text in the format:
|
1 2 3 4 5 |
[quoted name] [dataType][optional comment] |
|
Note
|
|
spark技术分享