关注 spark技术分享,
撸spark源码 玩spark最佳实践

StructType

StructType — Data Type for Schema Definition

StructType is a built-in data type that is a collection of StructFields.

StructType is used to define a schema or its part.

You can compare two StructType instances to see whether they are equal.

StructType presents itself as <struct> or STRUCT in query plans or SQL.

Note

StructType is a Seq[StructField] and therefore all things Seq apply equally here.

Read the official documentation of Scala’s scala.collection.Seq.

As of Spark 2.4.0, StructType can be converted to DDL format using toDDL method.

fromAttributes Method

fromAttributes…​FIXME

Note
fromAttributes is used when…​FIXME

toAttributes Method

toAttributes…​FIXME

Note
toAttributes is used when…​FIXME

Adding Fields to Schema — add Method

You can add a new StructField to your StructType. There are different variants of add method that all make for a new StructType with the field added.

DataType Name Conversions

StructType as a custom DataType is used in query plans or SQL. It can present itself using simpleString, catalogString or sql (see DataType Contract).

Accessing StructField — apply Method

StructType defines its own apply method that gives you an easy access to a StructField by name.

Creating StructType from Existing StructType — apply Method

This variant of apply lets you create a StructType out of an existing StructType with the names only.

It will throw an IllegalArgumentException exception when a field could not be found.

Displaying Schema As Tree — printTreeString Method

printTreeString prints out the schema to standard output.

Internally, it uses treeString method to build the tree and then println it.

Creating StructType For DDL-Formatted Text — fromDDL Object Method

fromDDL…​FIXME

Note
fromDDL is used when…​FIXME

Converting to DDL Format — toDDL Method

toDDL converts all the fields to DDL format and concatenates them using the comma (,).

赞(0) 打赏
未经允许不得转载:spark技术分享 » StructType
分享到: 更多 (0)

关注公众号:spark技术分享

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏