MaxGekk opened a new pull request #30963:
URL: https://github.com/apache/spark/pull/30963


   ### What changes were proposed in this pull request?
   1. Replace `SessionCatalogAndNamespace` by `DatabaseInSessionCatalog` in 
resolving database name from v1 session catalog.
   2. Throw more precise errors from `DatabaseInSessionCatalog`
   3. Fix expected error messages in `v1.ShowTablesSuiteBase`
   
   Closes #30947
   
   ### Why are the changes needed?
   Current error message "multi-part identifier cannot be empty" may confuse 
users. And this error message is just a consequence of "incorrectly" applied an 
implicit class. For example, `SHOW TABLES IN spark_catalog`:
   
   1. Spark cuts off `spark_catalog` from namespaces in 
`SessionCatalogAndNamespace`, so, `ns == Seq.empty` here: 
https://github.com/apache/spark/blob/0617dfce7beb34662ab30a607721e9b46e65c21e/sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala#L365
   2. Then `ns.length != 1` is `true` and Spark tries to raise the exception at 
https://github.com/apache/spark/blob/0617dfce7beb34662ab30a607721e9b46e65c21e/sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala#L367
   3.  ... but `ns.quoted` triggers implicit wrapping `Seq.empty` by 
`MultipartIdentifierHelper`, and hit to the second check `if (parts.isEmpty)` 
at 
https://github.com/apache/spark/blob/156704ba0dfcae39a80b8f0ce778b73913db03b2/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/CatalogV2Implicits.scala#L120-L122
   
   So, Spark throws the exception at third step instead of `new 
AnalysisException(s"The database name is not valid: $quoted")` on the second 
step. And even on the second step, the exception doesn't show actual reason as 
it is pretty generic.
   
   
   ### Does this PR introduce _any_ user-facing change?
   Yes in the case of v1 DDL commands when a database is not specified or 
nested databases is set.
   
   ### How was this patch tested?
   By running the affected test suites:
   ```
   $ build/sbt -Phive-2.3 -Phive-thriftserver "test:testOnly *DDLSuite"
   $ build/sbt -Phive-2.3 -Phive-thriftserver "test:testOnly *ShowTablesSuite"
   ```


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to