|
1 | 1 | # AppendData Logical Command |
2 | 2 |
|
3 | | -`AppendData` is a <<spark-sql-LogicalPlan.md#, logical operator>> that represents appending data (the result of executing a <<query, structured query>>) to a <<table, table>> (with the <<isByName, columns matching>> by <<byName, name>> or <<byPosition, position>>) in [DataSource V2](../new-and-noteworthy/datasource-v2.md). |
| 3 | +`AppendData` is a [V2WriteCommand](V2WriteCommand.md) that represents appending data (the result of executing a [structured query](#query)) to a [table](#table) (with the [columns matching](#isByName) by [name](#byName) or [position](#byPosition)). |
4 | 4 |
|
5 | | -`AppendData` is <<creating-instance, created>> (indirectly via <<byName, byName>> or <<byPosition, byPosition>> factory methods) only for tests. |
| 5 | +!!! note |
| 6 | + `AppendData` has replaced the deprecated [WriteToDataSourceV2](WriteToDataSourceV2.md) logical operator. |
6 | 7 |
|
7 | | -NOTE: `AppendData` has replaced the deprecated <<WriteToDataSourceV2.md#, WriteToDataSourceV2>> logical operator. |
| 8 | +## Creating Instance |
8 | 9 |
|
9 | | -[[creating-instance]] |
10 | 10 | `AppendData` takes the following to be created: |
11 | 11 |
|
12 | | -* [[table]] `NamedRelation` for the table (to append data to) |
13 | | -* [[query]] <<spark-sql-LogicalPlan.md#, Logical operator>> (for the query) |
14 | | -* [[isByName]] `isByName` flag |
| 12 | +* <span id="table"> [NamedRelation](NamedRelation.md) for the table (to append data to) |
| 13 | +* <span id="query"> Query ([LogicalPlan](LogicalPlan.md)) |
| 14 | +* <span id="writeOptions"> Write Options (`Map[String, String]`) |
| 15 | +* [isByName](#isByName) flag |
| 16 | +* <span id="write"> [Write](../connector/Write.md) |
15 | 17 |
|
16 | | -[[children]] |
17 | | -`AppendData` has a [single child logical operator](../catalyst/TreeNode.md#children) that is exactly the <<query, logical operator>>. |
| 18 | +`AppendData` is created using [byName](#byName) and [byPosition](#byPosition) operators. |
18 | 19 |
|
19 | | -`AppendData` is resolved by [ResolveOutputRelation](../logical-analysis-rules/ResolveOutputRelation.md) logical resolution rule. |
| 20 | +## <span id="isByName"> isByName flag |
20 | 21 |
|
21 | | -`AppendData` is planned (_replaced_) to <<WriteToDataSourceV2Exec.md#, WriteToDataSourceV2Exec>> physical operator (when the <<table, table>> is a <<DataSourceV2Relation.md#, DataSourceV2Relation>> logical operator). |
| 22 | +`AppendData` is given `isByName` flag when [created](#creating-instance). |
22 | 23 |
|
23 | | -=== [[byName]] `byName` Factory Method |
| 24 | +`isByName` is part of the [V2WriteCommand](V2WriteCommand.md#isByName) abstraction. |
24 | 25 |
|
25 | | -[source, scala] |
26 | | ----- |
27 | | -byName(table: NamedRelation, df: LogicalPlan): AppendData |
28 | | ----- |
| 26 | +## <span id="byName"> byName |
29 | 27 |
|
30 | | -`byName` simply creates a <<AppendData, AppendData>> logical operator with the <<isByName, isByName>> flag on (`true`). |
| 28 | +```scala |
| 29 | +byName( |
| 30 | + table: NamedRelation, |
| 31 | + df: LogicalPlan, |
| 32 | + writeOptions: Map[String, String] = Map.empty): AppendData |
| 33 | +``` |
31 | 34 |
|
32 | | -NOTE: `byName` seems used only for tests. |
| 35 | +`byName` creates a [AppendData](#creating-instance) with the [isByName](#isByName) flag enabled (`true`). |
33 | 36 |
|
34 | | -=== [[byPosition]] `byPosition` Factory Method |
| 37 | +`byName` is used when: |
35 | 38 |
|
36 | | -[source, scala] |
37 | | ----- |
38 | | -byPosition(table: NamedRelation, query: LogicalPlan): AppendData |
39 | | ----- |
| 39 | +* `DataFrameWriter` is requested to [saveInternal](../DataFrameWriter.md#saveInternal) (with `SaveMode.Append` mode) and [saveAsTable](../DataFrameWriter.md#saveAsTable) (with `SaveMode.Append` mode) |
| 40 | +* `DataFrameWriterV2` is requested to [append](../DataFrameWriterV2.md#append) |
40 | 41 |
|
41 | | -`byPosition` simply creates a <<AppendData, AppendData>> logical operator with the <<isByName, isByName>> flag off (`false`). |
| 42 | +## <span id="byPosition"> byPosition |
42 | 43 |
|
43 | | -NOTE: `byPosition` seems used only for tests. |
| 44 | +```scala |
| 45 | +byPosition( |
| 46 | + table: NamedRelation, |
| 47 | + query: LogicalPlan, |
| 48 | + writeOptions: Map[String, String] = Map.empty): AppendData |
| 49 | +``` |
| 50 | + |
| 51 | +`byPosition` creates a [AppendData](#creating-instance) with the [isByName](#isByName) flag disabled (`false`). |
| 52 | + |
| 53 | +`byPosition` is used when: |
| 54 | + |
| 55 | +* [ResolveInsertInto](../logical-analysis-rules/ResolveInsertInto.md) logical resolution rule is executed |
| 56 | +* `DataFrameWriter` is requested to [insertInto](../DataFrameWriter.md#insertInto) |
| 57 | + |
| 58 | +## Query Planning |
| 59 | + |
| 60 | +`AppendData` is planned to one of the physical operators in [DataSourceV2Strategy](../execution-planning-strategies/DataSourceV2Strategy.md) execution planning strategy: |
| 61 | + |
| 62 | +* `AppendDataExecV1` |
| 63 | +* `AppendDataExec` |
0 commit comments