Skip to content

Commit a76a399

Browse files
AppendData Logical Command
1 parent 97325e3 commit a76a399

File tree

3 files changed

+51
-27
lines changed

3 files changed

+51
-27
lines changed

docs/logical-analysis-rules/ResolveInsertInto.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ResolveInsertInto Logical Resolution Rule
22

3-
`ResolveInsertInto` is a logical rule (`Rule[LogicalPlan]`).
3+
`ResolveInsertInto` is a logical resolution rule (`Rule[LogicalPlan]`).
44

55
`ResolveInsertInto` is part of [Resolution](../Analyzer.md#Resolution) batch of [Logical Analyzer](../Analyzer.md).
66

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,63 @@
11
# AppendData Logical Command
22

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)).
44

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.
67

7-
NOTE: `AppendData` has replaced the deprecated <<WriteToDataSourceV2.md#, WriteToDataSourceV2>> logical operator.
8+
## Creating Instance
89

9-
[[creating-instance]]
1010
`AppendData` takes the following to be created:
1111

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)
1517

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.
1819

19-
`AppendData` is resolved by [ResolveOutputRelation](../logical-analysis-rules/ResolveOutputRelation.md) logical resolution rule.
20+
## <span id="isByName"> isByName flag
2021

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).
2223

23-
=== [[byName]] `byName` Factory Method
24+
`isByName` is part of the [V2WriteCommand](V2WriteCommand.md#isByName) abstraction.
2425

25-
[source, scala]
26-
----
27-
byName(table: NamedRelation, df: LogicalPlan): AppendData
28-
----
26+
## <span id="byName"> byName
2927

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+
```
3134

32-
NOTE: `byName` seems used only for tests.
35+
`byName` creates a [AppendData](#creating-instance) with the [isByName](#isByName) flag enabled (`true`).
3336

34-
=== [[byPosition]] `byPosition` Factory Method
37+
`byName` is used when:
3538

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)
4041

41-
`byPosition` simply creates a <<AppendData, AppendData>> logical operator with the <<isByName, isByName>> flag off (`false`).
42+
## <span id="byPosition"> byPosition
4243

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`

docs/logical-operators/V2WriteCommand.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# V2WriteCommand Logical Commands
22

3-
`V2WriteCommand` is an [extension](#contract) of the [Command](Command.md) abstraction for [commands](#implementations) that write [data](#query) to [tables](#table) in [DataSource V2](../new-and-noteworthy/datasource-v2.md).
3+
`V2WriteCommand` is an [extension](#contract) of the [Command](Command.md) abstraction for [logical commands](#implementations) that write [data](#query) to [tables](#table) in [DataSource V2](../new-and-noteworthy/datasource-v2.md).
44

55
## Contract
66

@@ -10,6 +10,10 @@
1010
isByName: Boolean
1111
```
1212

13+
Used when:
14+
15+
* [ResolveOutputRelation](../logical-analysis-rules/ResolveOutputRelation.md) logical resolution rule is executed (for `TableOutputResolver` to `resolveOutputColumns`)
16+
1317
### <span id="query"> Query
1418

1519
```scala

0 commit comments

Comments
 (0)