You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "AbinayaJayaprakasam (via GitHub)" <gi...@apache.org> on 2025/11/27 18:28:40 UTC
[PR] [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState [spark]
AbinayaJayaprakasam opened a new pull request, #53251:
URL: https://github.com/apache/spark/pull/53251
### What changes were proposed in this pull request?
I renamed _LEGACY_ERROR_TEMP_1007 to TEMP_VIEW_WRITE_NOT_ALLOWED and added sqlState 42623.
The changes include:
- New error class TEMP_VIEW_WRITE_NOT_ALLOWED in error-conditions.json with sqlState 42623
- Updated QueryCompilationErrors.scala to reference the new error class
- Refactored 3 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 3 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> 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)
<img width="452" height="354" alt="image" src="https://github.com/user-attachments/assets/f7fc3091-e54b-4401-8b8e-49c56a38d251" />
**After (new error with class and sqlState):**
scala> spark.table("source").writeTo("temp_view").append()
org.apache.spark.sql.AnalysisException: [TEMP_VIEW_WRITE_NOT_ALLOWED] Cannot write into temp view temp_view as it's not a data source v2 relation. SQLSTATE: 42623
at org.apache.spark.sql.errors.QueryCompilationErrors$.writeIntoTempViewNotAllowedError(QueryCompilationErrors.scala:551)
<img width="452" height="329" alt="image" src="https://github.com/user-attachments/assets/81730413-6690-4993-85db-7c3283a982b8" />
*Note: The error now displays the error class `[TEMP_VIEW_WRITE_NOT_ALLOWED]` and includes sqlState `42623` (accessible via `getSqlState()`).*
Ran the full DataFrameWriterV2Suite test suite: all tests pass successfully
<img width="452" height="108" alt="image" src="https://github.com/user-attachments/assets/a69161a8-5bd7-4f57-8c41-fede22afe950" />
### Was this patch authored or co-authored using generative AI tooling?
No
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'common/utils/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as new features, bug fixes, or other behavior changes. Documentation-only updates are not considered user-facing changes.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState [spark]
Posted by "AbinayaJayaprakasam (via GitHub)" <gi...@apache.org>.
AbinayaJayaprakasam commented on code in PR #53251:
URL: https://github.com/apache/spark/pull/53251#discussion_r2609938948
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -6029,6 +6029,12 @@
],
"sqlState" : "428EK"
},
+ "TEMP_VIEW_WRITE_NOT_ALLOWED" : {
+ "message" : [
+ "Cannot write into temp view <quoted> as it's not a data source v2 relation."
Review Comment:
Hi @cloud-fan .. Thanks a lot for reviewing this
No, there is no V1 version of this error.
Per my understanding the V1 API (DataFrameWriter.saveAsTable()) behaves differently: it allows writing when a temp view with the same name exists.
https://github.com/apache/spark/blob/master/sql/core/src/test/scala/org/apache/spark/sql/test/DataFrameReaderWriterSuite.scala#L923-L933
The error being renamed in this PR is specific to the V2 API (DataFrameWriterV2.writeTo()), which has stricter requirements: it only works with DataSource V2 relations, and temp views don't qualify.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState [spark]
Posted by "AbinayaJayaprakasam (via GitHub)" <gi...@apache.org>.
AbinayaJayaprakasam commented on code in PR #53251:
URL: https://github.com/apache/spark/pull/53251#discussion_r2569842106
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -6029,6 +6029,12 @@
],
"sqlState" : "428EK"
},
+ "TEMP_VIEW_WRITE_NOT_ALLOWED" : {
+ "message" : [
+ "Cannot write into temp view <quoted> as it's not a data source v2 relation."
+ ],
+ "sqlState" : "42623"
Review Comment:
Thank you .. You're absolutely right.
I initially chose 42623 because I saw it used for other write constraint errors in Spark, but after reviewing the SQL state definitions, 42809 ("The identified object is not the type of object to which the statement applies") is indeed more semantically accurate for this error.
The error occurs because the temp view is not a DataSource V2 relation, which is exactly an "object type mismatch" scenario that 42809 is designed for.
I've updated the PR to use 42809. Thank you for the careful review!
**References:**
- IBM DB2: [42809 - Wrong object type](https://www.ibm.com/docs/en/db2/11.5?topic=messages-sqlstate)
- PostgreSQL: [42809 - Wrong object type](https://www.postgresql.org/docs/current/errcodes-appendix.html)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #53251: [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState
URL: https://github.com/apache/spark/pull/53251
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #53251:
URL: https://github.com/apache/spark/pull/53251#discussion_r2618452062
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -7404,6 +7404,12 @@
],
"sqlState" : "42P01"
},
+ "VIEW_WRITE_NOT_ALLOWED" : {
+ "message" : [
+ "Cannot write into view <quoted> as it's not a data source v2 relation."
Review Comment:
can we make the error message more general? I think the v1 message is good:
```
Cannot write into view <identifier>, please write into a table instead.
```
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -7404,6 +7404,12 @@
],
"sqlState" : "42P01"
},
+ "VIEW_WRITE_NOT_ALLOWED" : {
+ "message" : [
+ "Cannot write into view <quoted> as it's not a data source v2 relation."
Review Comment:
can we make the error message more general?
```
Cannot write into view <identifier>, please write into a table instead.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #53251:
URL: https://github.com/apache/spark/pull/53251#discussion_r2609436768
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -6029,6 +6029,12 @@
],
"sqlState" : "428EK"
},
+ "TEMP_VIEW_WRITE_NOT_ALLOWED" : {
+ "message" : [
+ "Cannot write into temp view <quoted> as it's not a data source v2 relation."
Review Comment:
is there a v1 version of this error? what's the error message?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState [spark]
Posted by "AbinayaJayaprakasam (via GitHub)" <gi...@apache.org>.
AbinayaJayaprakasam commented on code in PR #53251:
URL: https://github.com/apache/spark/pull/53251#discussion_r2616442786
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -6029,6 +6029,12 @@
],
"sqlState" : "428EK"
},
+ "TEMP_VIEW_WRITE_NOT_ALLOWED" : {
+ "message" : [
+ "Cannot write into temp view <quoted> as it's not a data source v2 relation."
Review Comment:
@cloud-fan Thanks for the feedback! I’ve updated the PR to reuse the existing VIEW_WRITE_NOT_ALLOWED error instead of introducing a new one. Please let me know if there’s anything further to address.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #53251:
URL: https://github.com/apache/spark/pull/53251#discussion_r2618452062
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -7404,6 +7404,12 @@
],
"sqlState" : "42P01"
},
+ "VIEW_WRITE_NOT_ALLOWED" : {
+ "message" : [
+ "Cannot write into view <quoted> as it's not a data source v2 relation."
Review Comment:
can we make the error message more general?
```
Cannot write into view <name>, please write into a table instead.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #53251:
URL: https://github.com/apache/spark/pull/53251#issuecomment-3666159606
the failed JDBC test is unrelated, thanks, merging to master!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState [spark]
Posted by "AbinayaJayaprakasam (via GitHub)" <gi...@apache.org>.
AbinayaJayaprakasam commented on PR #53251:
URL: https://github.com/apache/spark/pull/53251#issuecomment-3668461071
Thank you so much @cloud-fan and @vinodkc for reviewing this PR
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState [spark]
Posted by "vinodkc (via GitHub)" <gi...@apache.org>.
vinodkc commented on code in PR #53251:
URL: https://github.com/apache/spark/pull/53251#discussion_r2569836360
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -6029,6 +6029,12 @@
],
"sqlState" : "428EK"
},
+ "TEMP_VIEW_WRITE_NOT_ALLOWED" : {
+ "message" : [
+ "Cannot write into temp view <quoted> as it's not a data source v2 relation."
+ ],
+ "sqlState" : "42623"
Review Comment:
Can you explain the choice of sqlState 42623? The definition is "DEFAULT clause cannot be specified", which doesn't seem to match this error's purpose. Have you considered 42809 instead?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #53251:
URL: https://github.com/apache/spark/pull/53251#discussion_r2610436056
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -6029,6 +6029,12 @@
],
"sqlState" : "428EK"
},
+ "TEMP_VIEW_WRITE_NOT_ALLOWED" : {
+ "message" : [
+ "Cannot write into temp view <quoted> as it's not a data source v2 relation."
Review Comment:
I found the v1 error: https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala#L1220
Can we reuse it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-54541][SQL] Rename _LEGACY_ERROR_TEMP_1007 and add sqlState [spark]
Posted by "AbinayaJayaprakasam (via GitHub)" <gi...@apache.org>.
AbinayaJayaprakasam commented on PR #53251:
URL: https://github.com/apache/spark/pull/53251#issuecomment-3603246086
@dongjoon-hyun , Could you please review this PR?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org