Commit be675a0
[SPARK-34490][SQL] Analysis should fail if the view refers a dropped table
### What changes were proposed in this pull request?
When resolving a view, we use the captured view name in `AnalysisContext` to
distinguish whether a relation name is a view or a table. But if the resolution failed,
other rules (e.g. `ResolveTables`) will try to resolve the relation again but without
`AnalysisContext`. So, in this case, the resolution may be incorrect. For example,
if the view refers to a dropped table while a view with the same name exists, the
dropped table will be resolved as a view rather than an unresolved exception.
### Why are the changes needed?
bugfix
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
newly added test cases
Closes apache#31606 from linhongliu-db/fix-temp-view-master.
Lead-authored-by: Linhong Liu <linhong.liu@databricks.com>
Co-authored-by: Linhong Liu <67896261+linhongliu-db@users.noreply.github.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>1 parent 612d523 commit be675a0
File tree
3 files changed
+53
-15
lines changed- sql
- catalyst/src
- main/scala/org/apache/spark/sql/catalyst/analysis
- test/scala/org/apache/spark/sql/catalyst/analysis
- core/src/test/scala/org/apache/spark/sql/execution
3 files changed
+53
-15
lines changedLines changed: 23 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
871 | 871 | | |
872 | 872 | | |
873 | 873 | | |
874 | | - | |
| 874 | + | |
875 | 875 | | |
876 | | - | |
| 876 | + | |
877 | 877 | | |
878 | 878 | | |
879 | 879 | | |
880 | | - | |
| 880 | + | |
881 | 881 | | |
882 | 882 | | |
883 | 883 | | |
884 | | - | |
| 884 | + | |
885 | 885 | | |
886 | 886 | | |
887 | 887 | | |
888 | 888 | | |
889 | 889 | | |
890 | 890 | | |
891 | | - | |
| 891 | + | |
892 | 892 | | |
893 | 893 | | |
894 | 894 | | |
| |||
921 | 921 | | |
922 | 922 | | |
923 | 923 | | |
924 | | - | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
925 | 927 | | |
926 | 928 | | |
927 | 929 | | |
| |||
934 | 936 | | |
935 | 937 | | |
936 | 938 | | |
937 | | - | |
| 939 | + | |
938 | 940 | | |
939 | 941 | | |
940 | 942 | | |
| |||
1098 | 1100 | | |
1099 | 1101 | | |
1100 | 1102 | | |
1101 | | - | |
| 1103 | + | |
1102 | 1104 | | |
1103 | 1105 | | |
1104 | 1106 | | |
| |||
1115 | 1117 | | |
1116 | 1118 | | |
1117 | 1119 | | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
1118 | 1129 | | |
1119 | 1130 | | |
1120 | | - | |
| 1131 | + | |
1121 | 1132 | | |
1122 | 1133 | | |
1123 | 1134 | | |
| |||
1137 | 1148 | | |
1138 | 1149 | | |
1139 | 1150 | | |
1140 | | - | |
| 1151 | + | |
1141 | 1152 | | |
1142 | 1153 | | |
1143 | 1154 | | |
1144 | 1155 | | |
1145 | 1156 | | |
1146 | 1157 | | |
1147 | | - | |
| 1158 | + | |
1148 | 1159 | | |
1149 | 1160 | | |
1150 | 1161 | | |
| |||
1170 | 1181 | | |
1171 | 1182 | | |
1172 | 1183 | | |
1173 | | - | |
| 1184 | + | |
1174 | 1185 | | |
1175 | 1186 | | |
1176 | 1187 | | |
| |||
Lines changed: 10 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | | - | |
31 | | - | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
49 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
50 | 57 | | |
51 | 58 | | |
52 | 59 | | |
| |||
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
261 | 281 | | |
262 | 282 | | |
263 | 283 | | |
| |||
0 commit comments