You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/logical-operators/Except.md
+37-48Lines changed: 37 additions & 48 deletions
Original file line number
Diff line number
Diff line change
@@ -4,61 +4,48 @@ title: Except
4
4
5
5
# Except Logical Operator
6
6
7
-
`Except` is a spark-sql-LogicalPlan.md#BinaryNode[binary logical operator] that represents the following high-level operators in a logical plan:
7
+
`Except` is a `SetOperation`binary logical operator that represents the following high-level operators (in a logical plan):
8
8
9
-
*`EXCEPT [ DISTINCT | ALL ]` and `MINUS [ DISTINCT | ALL ]` SQL statements (cf. sql/AstBuilder.md#visitSetOperation[AstBuilder])
9
+
*`EXCEPT [ DISTINCT | ALL ]` and `MINUS [ DISTINCT | ALL ]` SQL statements (cf. [AstBuilder](../sql/AstBuilder.md#visitSetOperation))
10
+
*[Dataset.except](../Dataset.md#except) and [Dataset.exceptAll](../Dataset.md#exceptAll)
10
11
11
-
* spark-sql-dataset-operators.md#except[Dataset.except] and spark-sql-dataset-operators.md#exceptAll[Dataset.exceptAll]
12
+
## Creating Instance
12
13
13
-
`Except` is supposed to be resolved (_optimized_) to <<logical-conversions, other logical commands>> at logical optimization phase (i.e. `Except` should not be part of a logical plan after logical optimization). [BasicOperators](../execution-planning-strategies/BasicOperators.md) execution planning strategy throws an `IllegalStateException` if conversions did not happen.
14
-
15
-
[[logical-conversions]]
16
-
.Except's Logical Resolutions (Conversions)
17
-
[cols="30,70",options="header",width="100%"]
18
-
|===
19
-
| Target Logical Operators
20
-
| Optimization Rules and Demos
21
-
22
-
| Left-Anti Join.md[Join]
23
-
| `Except` (DISTINCT) in ReplaceExceptWithAntiJoin.md[ReplaceExceptWithAntiJoin] logical optimization rule
24
-
25
-
Consult <<demo-left-anti-join, Demo: Except Operator Replaced with Left-Anti Join>>
26
-
27
-
| `Filter`
28
-
| `Except` (DISTINCT) in [ReplaceExceptWithFilter](../logical-optimizations/ReplaceExceptWithFilter.md) logical optimization rule
29
-
30
-
Consult <<demo-except-filter, Demo: Except Operator Replaced with Filter Operator>>
14
+
`Except` takes the following to be created:
31
15
32
-
| `Union`, Aggregate.md[Aggregate] and Generate.md[Generate]
33
-
| `Except` (ALL) in RewriteExceptAll.md[RewriteExceptAll] logical optimization rule
16
+
* <spanid="left"> Left [logical operator](LogicalPlan.md)
17
+
* <spanid="right"> Right [logical operator](LogicalPlan.md)
18
+
* <spanid="isAll"> `isAll` flag for `DISTINCT` (`false`) or `ALL` (`true`)
34
19
35
-
Consult <<demo-except-all, Demo: Except (All) Operator Replaced with Union, Aggregate and Generate Operators>>
20
+
`Except` is created when:
36
21
37
-
|===
22
+
*`AstBuilder` is requested to [visit a SetOperation](../sql/AstBuilder.md#visitSetOperation) (`EXCEPT` and `MINUS` operators)
23
+
*[Dataset.except](../Dataset.md#except) and [Dataset.exceptAll](../Dataset.md#exceptAll) operators are used
24
+
* Catalyst DSL's [except](../catalyst-dsl/DslLogicalPlan.md#except) operator is used
38
25
39
-
The types of the <<left, left>> and <<right, right>> logical (sub)operators can be widen in `WidenSetOperationTypes` logical analysis type-coercion rule.
`Except` is supposed to be resolved (_optimized_) to other logical commands at logical optimization phase (i.e. `Except` should not be part of a logical plan after logical optimization).
42
29
43
-
`Except` takes the following to be created:
30
+
[BasicOperators](../execution-planning-strategies/BasicOperators.md) execution planning strategy throws an `IllegalStateException` if conversions did not happen.
44
31
45
-
*[[left]] Left spark-sql-LogicalPlan.md[logical operator]
46
-
*[[right]] Right spark-sql-LogicalPlan.md[logical operator]
47
-
*[[isAll]]`isAll` flag for `DISTINCT` (`false`) or `ALL` (`true`)
32
+
Target Logical Operators | Optimization Rules and Demos
[Catalyst DSL](../catalyst-dsl/index.md) defines [except](../catalyst-dsl/index.md#except) extension method to create an `Except` logical operator, e.g. for testing or Spark SQL internals exploration.
46
+
[Catalyst DSL](../catalyst-dsl/index.md) defines [except](../catalyst-dsl/index.md#except) extension method to create an `Except` logical operator (e.g. for testing or Spark SQL internals exploration).
59
47
60
-
[source, plaintext]
61
-
----
48
+
```text
62
49
import org.apache.spark.sql.catalyst.dsl.plans._
63
50
val plan = table("a").except(table("b"), isAll = false)
=== [[CheckAnalysis]]Except Only on Relations with Same Number of Columns
61
+
## Except Only on Relations with Same Number of Columns { #CheckAnalysis }
75
62
76
-
`Except` logical operator can only be performed on CheckAnalysis.md#checkAnalysis[tables with the same number of columns].
63
+
`Except` logical operator can only be performed on [tables with the same number of columns](../CheckAnalysis.md#checkAnalysis).
77
64
78
-
```
65
+
```text
79
66
scala> left.except(right)
80
67
org.apache.spark.sql.AnalysisException: Except can only be performed on tables with the same number of columns, but the first table has 3 columns and the second table has 4 columns;;
81
68
'Except false
@@ -91,9 +78,11 @@ org.apache.spark.sql.AnalysisException: Except can only be performed on tables w
91
78
...
92
79
```
93
80
94
-
=== [[demo-left-anti-join]]Demo: Except Operator Replaced with Left-Anti Join
81
+
## Demo
95
82
96
-
```
83
+
### Except Operator Replaced with Left-Anti Join { #demo-left-anti-join }
0 commit comments