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

CreateViewCommand

CreateViewCommand Logical Command

CreateViewCommand is created to represent the following:

Caution
FIXME What’s the difference between CreateTempViewUsing?

CreateViewCommand works with different view types.

Table 1. CreateViewCommand Behaviour Per View Type
View Type Description / Side Effect

LocalTempView

A session-scoped local temporary view that is available until the session, that has created it, is stopped.

When executed, CreateViewCommand requests the current SessionCatalog to create a temporary view.

GlobalTempView

A cross-session global temporary view that is available until the Spark application stops.

When executed, CreateViewCommand requests the current SessionCatalog to create a global view.

PersistedView

A cross-session persisted view that is available until dropped.

When executed, CreateViewCommand checks if the table exists. If it does and replace is enabled CreateViewCommand requests the current SessionCatalog to alter a table. Otherwise, when the table does not exist, CreateViewCommand requests the current SessionCatalog to create it.

CreateViewCommand returns the child logical query plan when requested for the inner nodes (that should be shown as an inner nested tree of this node).

Creating CatalogTable — prepareTable Internal Method

prepareTable…​FIXME

Note
prepareTable is used exclusively when CreateViewCommand logical command is executed.

Executing Logical Command — run Method

Note
run is part of RunnableCommand Contract to execute (run) a logical command.

run requests the input SparkSession for the SessionState that is in turn requested to execute the child logical plan (which simply creates a QueryExecution).

Note

run uses a common idiom in Spark SQL to make sure that a logical plan can be analyzed, i.e.

run requests the input SparkSession for the SessionState that is in turn requested for the SessionCatalog.

run then branches off per the ViewType:

run throws an AnalysisException for persisted views when they already exist, the allowExisting flag is off and the table type is not a view.

run throws an AnalysisException for persisted views when they already exist and the allowExisting and replace flags are off.

run throws an AnalysisException if the userSpecifiedColumns are defined and their numbers is different from the number of output schema attributes of the analyzed logical plan.

Creating CreateViewCommand Instance

CreateViewCommand takes the following when created:

  • TableIdentifier

  • User-defined columns (as Seq[(String, Option[String])])

  • Optional comment

  • Properties (as Map[String, String])

  • Optional DDL statement

  • Child logical plan

  • allowExisting flag

  • replace flag

  • ViewType

verifyTemporaryObjectsNotExists Internal Method

verifyTemporaryObjectsNotExists…​FIXME

Note
verifyTemporaryObjectsNotExists is used exclusively when CreateViewCommand logical command is executed.

aliasPlan Internal Method

aliasPlan…​FIXME

Note
aliasPlan is used when CreateViewCommand logical command is executed (and prepareTable).
赞(0) 打赏
未经允许不得转载:spark技术分享 » CreateViewCommand
分享到: 更多 (0)

关注公众号:spark技术分享

联系我们联系我们

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

支付宝扫一扫打赏

微信扫一扫打赏