Commit 92d2a15
[SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState
### What changes were proposed in this pull request?
I renamed _LEGACY_ERROR_TEMP_1007 to VIEW_WRITE_NOT_ALLOWED and added sqlState 42809.
The changes include:
- New error class VIEW_WRITE_NOT_ALLOWED in error-conditions.json with sqlState 42809
- Updated QueryCompilationErrors.scala to reference the new error class
- Refactored 6 test cases in DataFrameWriterV2Suite to use checkError() instead of string matching
### Why are the changes needed?
Users frequently encounter this error when attempting to write to temporary views using the DataFrameWriter V2 API. The legacy error name is non-descriptive and lacks an sqlState, which makes it difficult to handle programatically and reduces compatibility with JDBC/ODBC clients.
### Does this PR introduce any user-facing change?
No. The error message text stays the same. User will only see the same error message, but the underlying error class is now properly named and includes a sqlState for better tooling support.
### How was this patch tested?
I tested this change in multiple ways:
- Manually triggered the error in spark-shell to verify the new error class is used
- Updated 6 existing tests in DataFrameWriterV2Suite to use checkError() for structured validation of error class and parameters
- Ran the full test suite: all tests pass successfully
#### Manual Testing in Spark-Shell
**Before (legacy error):**
```
scala> val sourceData = Seq((1, "a"), (2, "b"), (3, "c")).toDF("id", "name")
scala> sourceData.createOrReplaceTempView("source")
scala> spark.range(10).createOrReplaceTempView("temp_view")
scala> spark.table("source").writeTo("temp_view").append()
org.apache.spark.sql.AnalysisException: Cannot write into temp view temp_view as it's not a data source v2 relation.
at org.apache.spark.sql.errors.QueryCompilationErrors$.writeIntoTempViewNotAllowedError(QueryCompilationErrors.scala:551)
at org.apache.spark.sql.catalyst.analysis.Analyzer$ResolveRelations$$anonfun$apply$12.$anonfun$applyOrElse$73(Analyzer.scala:1237)
```
**After (new error with class and sqlState):**
```
scala> val sourceData = Seq((1, "a"), (2, "b"), (3, "c")).toDF("id", "name")
scala> sourceData.createOrReplaceTempView("source")
scala> spark.range(10).createOrReplaceTempView("temp_view")
scala> spark.table("source").writeTo("temp_view").append()
org.apache.spark.sql.AnalysisException: [VIEW_WRITE_NOT_ALLOWED] Cannot write into view temp_view, please write into a table instead. SQLSTATE: 42809
at org.apache.spark.sql.errors.QueryCompilationErrors$.writeIntoTempViewNotAllowedError(QueryCompilationErrors.scala:551)
at org.apache.spark.sql.catalyst.analysis.Analyzer$ResolveRelations$$anonfun$apply$12.$anonfun$applyOrElse$73(Analyzer.scala:1237)
```
*Note: The error now displays the error class `[VIEW_WRITE_NOT_ALLOWED]` and includes sqlState `42809` (accessible via `getSqlState()`).*
Ran the full DataFrameWriterV2Suite test suite: all tests pass successfully
```
[info] Test run finished: 0 failed, 0 ignored, 6 total, 0.602s
[info] ScalaTest
[info] Run completed in 8 seconds, 683 milliseconds.
[info] Total number of tests run: 48
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 48, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[info] Passed: Total 54, Failed 0, Errors 0, Passed 54
[success] Total time: 38 s, completed 13-Dec-2025, 10:51:11 pm
```
### Was this patch authored or co-authored using generative AI tooling?
No
Closes apache#53251 from AbinayaJayaprakasam/SPARK-fix-54541-PR.
Authored-by: AbinayaJayaprakasam <jaiabiman@gmail.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>1 parent e3569ba commit 92d2a15
File tree
3 files changed
+52
-41
lines changed- common/utils/src/main/resources/error
- sql
- catalyst/src/main/scala/org/apache/spark/sql/errors
- core/src/test/scala/org/apache/spark/sql
3 files changed
+52
-41
lines changedLines changed: 6 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7482 | 7482 | | |
7483 | 7483 | | |
7484 | 7484 | | |
| 7485 | + | |
| 7486 | + | |
| 7487 | + | |
| 7488 | + | |
| 7489 | + | |
| 7490 | + | |
7485 | 7491 | | |
7486 | 7492 | | |
7487 | 7493 | | |
| |||
7706 | 7712 | | |
7707 | 7713 | | |
7708 | 7714 | | |
7709 | | - | |
7710 | | - | |
7711 | | - | |
7712 | | - | |
7713 | | - | |
7714 | 7715 | | |
7715 | 7716 | | |
7716 | 7717 | | |
7717 | 7718 | | |
7718 | 7719 | | |
7719 | | - | |
7720 | | - | |
7721 | | - | |
7722 | | - | |
7723 | | - | |
7724 | 7720 | | |
7725 | 7721 | | |
7726 | 7722 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
550 | | - | |
551 | | - | |
| 550 | + | |
| 551 | + | |
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
| |||
578 | 578 | | |
579 | 579 | | |
580 | 580 | | |
581 | | - | |
582 | | - | |
| 581 | + | |
| 582 | + | |
583 | 583 | | |
584 | 584 | | |
585 | 585 | | |
| |||
Lines changed: 42 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
173 | 175 | | |
174 | 176 | | |
175 | 177 | | |
176 | 178 | | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
181 | 186 | | |
182 | 187 | | |
183 | 188 | | |
| |||
270 | 275 | | |
271 | 276 | | |
272 | 277 | | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
278 | 285 | | |
279 | 286 | | |
280 | 287 | | |
281 | 288 | | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
286 | 296 | | |
287 | 297 | | |
288 | 298 | | |
| |||
375 | 385 | | |
376 | 386 | | |
377 | 387 | | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
383 | 395 | | |
384 | 396 | | |
385 | 397 | | |
386 | 398 | | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
391 | 406 | | |
392 | 407 | | |
393 | 408 | | |
| |||
0 commit comments