-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-33872][SQL] Throw more specific exceptions when relations/namespaces are not found #30878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,10 +99,10 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog { | |
| throw QueryExecutionErrors.logicalPlanHaveOutputOfCharOrVarcharError(leaf) | ||
|
|
||
| case u: UnresolvedNamespace => | ||
| u.failAnalysis(s"Namespace not found: ${u.multipartIdentifier.quoted}") | ||
| throw new NoSuchNamespaceException(s"Namespace not found: ${u.multipartIdentifier.quoted}") | ||
|
|
||
| case u: UnresolvedTable => | ||
| u.failAnalysis(s"Table not found: ${u.multipartIdentifier.quoted}") | ||
| throw new NoSuchTableException(s"Table not found: ${u.multipartIdentifier.quoted}") | ||
|
|
||
| case u @ UnresolvedView(NonSessionCatalogAndIdentifier(catalog, ident), cmd, _, _) => | ||
| u.failAnalysis( | ||
|
|
@@ -111,43 +111,43 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog { | |
| s"$cmd expects a view.") | ||
|
|
||
| case u: UnresolvedView => | ||
| u.failAnalysis(s"View not found: ${u.multipartIdentifier.quoted}") | ||
| throw new NoSuchTableException(s"View not found: ${u.multipartIdentifier.quoted}") | ||
|
|
||
| case u: UnresolvedTableOrView => | ||
| val viewStr = if (u.allowTempView) "view" else "permanent view" | ||
| u.failAnalysis( | ||
| throw new NoSuchTableException( | ||
| s"Table or $viewStr not found: ${u.multipartIdentifier.quoted}") | ||
|
|
||
| case u: UnresolvedRelation => | ||
| u.failAnalysis(s"Table or view not found: ${u.multipartIdentifier.quoted}") | ||
| throw new NoSuchTableException(s"Table or view not found: ${u.multipartIdentifier.quoted}") | ||
|
|
||
| case InsertIntoStatement(u: UnresolvedRelation, _, _, _, _, _) => | ||
| failAnalysis(s"Table not found: ${u.multipartIdentifier.quoted}") | ||
| throw new NoSuchTableException(s"Table not found: ${u.multipartIdentifier.quoted}") | ||
|
|
||
| case CacheTable(u: UnresolvedRelation, _, _, _) => | ||
| failAnalysis(s"Table or view not found: ${u.multipartIdentifier.quoted}") | ||
| throw new NoSuchTableException(s"Table or view not found: ${u.multipartIdentifier.quoted}") | ||
|
|
||
| case UncacheTable(u: UnresolvedRelation, _, _) => | ||
| failAnalysis(s"Table or view not found: ${u.multipartIdentifier.quoted}") | ||
| throw new NoSuchTableException(s"Table or view not found: ${u.multipartIdentifier.quoted}") | ||
|
|
||
| // TODO (SPARK-27484): handle streaming write commands when we have them. | ||
| case write: V2WriteCommand if write.table.isInstanceOf[UnresolvedRelation] => | ||
| val tblName = write.table.asInstanceOf[UnresolvedRelation].multipartIdentifier | ||
| write.table.failAnalysis(s"Table or view not found: ${tblName.quoted}") | ||
| throw new NoSuchTableException(s"Table or view not found: ${tblName.quoted}") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to throw this exception at a specific node, or is it not needed? /** Fails the analysis at the point where a specific tree node was parsed. */
def failAnalysis(msg: String): Nothing = {
throw new AnalysisException(msg, t.origin.line, t.origin.startPosition)
} |
||
|
|
||
| case u: UnresolvedV2Relation if isView(u.originalNameParts) => | ||
| u.failAnalysis( | ||
| throw new NoSuchTableException( | ||
| s"Invalid command: '${u.originalNameParts.quoted}' is a view not a table.") | ||
|
|
||
| case u: UnresolvedV2Relation => | ||
| u.failAnalysis(s"Table not found: ${u.originalNameParts.quoted}") | ||
| throw new NoSuchTableException(s"Table not found: ${u.originalNameParts.quoted}") | ||
|
|
||
| case AlterTable(_, _, u: UnresolvedV2Relation, _) if isView(u.originalNameParts) => | ||
| u.failAnalysis( | ||
| s"Invalid command: '${u.originalNameParts.quoted}' is a view not a table.") | ||
|
|
||
| case AlterTable(_, _, u: UnresolvedV2Relation, _) => | ||
| failAnalysis(s"Table not found: ${u.originalNameParts.quoted}") | ||
| throw new NoSuchTableException(s"Table not found: ${u.originalNameParts.quoted}") | ||
|
|
||
| case operator: LogicalPlan => | ||
| // Check argument data types of higher-order functions downwards first. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One benefit of
u.failAnalysisis that it can report the error position in SQL string. If we can't keep this feature with the new exception, I'd suggest we don't change the exception type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we close this PR or update
NoSuchNamespaceExceptionandNoSuchTableExceptionto handle positions?Btw, it looks like there is a bug in keeping the position. I will fix it separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's easy to do, let's go for it. Otherwise, we can close this PR as exception type seems not a big deal to me.