Commit dfd7ac9
[SPARK-24781][SQL] Using a reference from Dataset in Filter/Sort might not work
## What changes were proposed in this pull request?
When we use a reference from Dataset in filter or sort, which was not used in the prior select, an AnalysisException occurs, e.g.,
```scala
val df = Seq(("test1", 0), ("test2", 1)).toDF("name", "id")
df.select(df("name")).filter(df("id") === 0).show()
```
```scala
org.apache.spark.sql.AnalysisException: Resolved attribute(s) id#6 missing from name#5 in operator !Filter (id#6 = 0).;;
!Filter (id#6 = 0)
+- AnalysisBarrier
+- Project [name#5]
+- Project [_1#2 AS name#5, _2#3 AS id#6]
+- LocalRelation [_1#2, _2#3]
```
This change updates the rule `ResolveMissingReferences` so `Filter` and `Sort` with non-empty `missingInputs` will also be transformed.
## How was this patch tested?
Added tests.
Author: Liang-Chi Hsieh <[email protected]>
Closes #21745 from viirya/SPARK-24781.1 parent 0f24c6f commit dfd7ac9
File tree
2 files changed
+48
-7
lines changed- sql
- catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis
- core/src/test/scala/org/apache/spark/sql
2 files changed
+48
-7
lines changedLines changed: 23 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1132 | 1132 | | |
1133 | 1133 | | |
1134 | 1134 | | |
1135 | | - | |
| 1135 | + | |
| 1136 | + | |
1136 | 1137 | | |
1137 | 1138 | | |
1138 | 1139 | | |
| |||
1143 | 1144 | | |
1144 | 1145 | | |
1145 | 1146 | | |
1146 | | - | |
| 1147 | + | |
1147 | 1148 | | |
1148 | 1149 | | |
1149 | 1150 | | |
| |||
1154 | 1155 | | |
1155 | 1156 | | |
1156 | 1157 | | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
1157 | 1164 | | |
1158 | 1165 | | |
1159 | | - | |
1160 | | - | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
1161 | 1169 | | |
1162 | 1170 | | |
1163 | 1171 | | |
| |||
1168 | 1176 | | |
1169 | 1177 | | |
1170 | 1178 | | |
| 1179 | + | |
1171 | 1180 | | |
| 1181 | + | |
1172 | 1182 | | |
1173 | | - | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
1174 | 1186 | | |
1175 | 1187 | | |
1176 | 1188 | | |
1177 | 1189 | | |
1178 | 1190 | | |
1179 | | - | |
| 1191 | + | |
1180 | 1192 | | |
1181 | 1193 | | |
1182 | 1194 | | |
| |||
1526 | 1538 | | |
1527 | 1539 | | |
1528 | 1540 | | |
1529 | | - | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
1530 | 1546 | | |
1531 | 1547 | | |
1532 | 1548 | | |
| |||
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2387 | 2387 | | |
2388 | 2388 | | |
2389 | 2389 | | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
2390 | 2415 | | |
0 commit comments