GitHub user gatorsmile opened a pull request: https://github.com/apache/spark/pull/19723
[BACKPORT-2.2] [SPARK-22488][SQL] Fix the view resolution issue in the SparkSession internal table() API ## What changes were proposed in this pull request? The current internal `table()` API of `SparkSession` bypasses the Analyzer and directly calls `sessionState.catalog.lookupRelation` API. This skips the view resolution logics in our Analyzer rule `ResolveRelations`. This internal API is widely used by various DDL commands, public and internal APIs. Users might get the strange error caused by view resolution when the default database is different. ``` Table or view not found: t1; line 1 pos 14 org.apache.spark.sql.AnalysisException: Table or view not found: t1; line 1 pos 14 at org.apache.spark.sql.catalyst.analysis.package$AnalysisErrorAt.failAnalysis(package.scala:42) ``` This PR is to fix it by enforcing it to use `ResolveRelations` to resolve the table. ## How was this patch tested? Added a test case and modified the existing test cases You can merge this pull request into a Git repository by running: $ git pull https://github.com/gatorsmile/spark backport22488 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/spark/pull/19723.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #19723 ---- commit e8f6dbb12aa026ffc4c00d2dd9553c3a0c3b10a7 Author: gatorsmile <gatorsm...@gmail.com> Date: 2017-11-11T17:20:11Z [SPARK-22488][SQL] Fix the view resolution issue in the SparkSession internal table() API The current internal `table()` API of `SparkSession` bypasses the Analyzer and directly calls `sessionState.catalog.lookupRelation` API. This skips the view resolution logics in our Analyzer rule `ResolveRelations`. This internal API is widely used by various DDL commands, public and internal APIs. Users might get the strange error caused by view resolution when the default database is different. ``` Table or view not found: t1; line 1 pos 14 org.apache.spark.sql.AnalysisException: Table or view not found: t1; line 1 pos 14 at org.apache.spark.sql.catalyst.analysis.package$AnalysisErrorAt.failAnalysis(package.scala:42) ``` This PR is to fix it by enforcing it to use `ResolveRelations` to resolve the table. Added a test case and modified the existing test cases Author: gatorsmile <gatorsm...@gmail.com> Closes #19713 from gatorsmile/viewResolution. ---- --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org