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

InsertIntoTable

InsertIntoTable Unary Logical Operator

InsertIntoTable is a unary logical operator that represents the following:

InsertIntoTable is created with partition keys that correspond to the partitionSpec part of the following SQL statements:

InsertIntoTable has no partition keys when created as follows:

InsertIntoTable can never be resolved (i.e. InsertIntoTable should not be part of a logical plan after analysis and is supposed to be converted to logical commands at analysis phase).

Table 1. InsertIntoTable’s Logical Resolutions (Conversions)
Logical Command Description

InsertIntoHiveTable

When HiveAnalysis resolution rule transforms InsertIntoTable with a HiveTableRelation

InsertIntoDataSourceCommand

When DataSourceAnalysis posthoc logical resolution resolves an InsertIntoTable with a LogicalRelation over an InsertableRelation (with no partitions defined)

InsertIntoHadoopFsRelationCommand

When DataSourceAnalysis posthoc logical resolution transforms InsertIntoTable with a LogicalRelation over a HadoopFsRelation

Caution
FIXME What’s the difference between HiveAnalysis that converts InsertIntoTable(r: HiveTableRelation…​) to InsertIntoHiveTable and RelationConversions that converts InsertIntoTable(r: HiveTableRelation,…​) to InsertIntoTable (with LogicalRelation)?
Note
Inserting into views or RDD-based tables is not allowed (and fails at analysis).

InsertIntoTable (with UnresolvedRelation leaf logical operator) is created when:

InsertIntoTable has an empty output schema.

Tip

Use insertInto operator from the Catalyst DSL to create an InsertIntoTable logical operator, e.g. for testing or Spark SQL internals exploration.

Creating InsertIntoTable Instance

InsertIntoTable takes the following when created:

  • Logical plan for the table to insert into

  • Partition keys (with optional partition values for dynamic partition insert)

  • Logical plan representing the data to be written

  • overwrite flag that indicates whether to overwrite an existing table or partitions (true) or not (false)

  • ifPartitionNotExists flag

Inserting Into View Not Allowed

Inserting into a view is not allowed, i.e. a query plan with an InsertIntoTable operator with a UnresolvedRelation leaf operator that is resolved to a View unary operator fails at analysis (when ResolveRelations logical resolution is executed).

Inserting Into RDD-Based Table Not Allowed

Inserting into an RDD-based table is not allowed, i.e. a query plan with an InsertIntoTable operator with one of the following logical operators (as the logical plan representing the table) fails at analysis (when PreWriteCheck extended logical check is executed):

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

关注公众号:spark技术分享

联系我们联系我们

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

支付宝扫一扫打赏

微信扫一扫打赏