Skip to content
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

[SPARK-33575][SQL] Fix misleading exception for "ANALYZE TABLE ... FOR COLUMNS" on temporary views #30519

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ case class AnalyzeColumnCommand(

private def analyzeColumnInTempView(plan: LogicalPlan, sparkSession: SparkSession): Unit = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that analyzeColumnInTempView is called only if temp view (including global) exists:

case Some(db) if db == sparkSession.sharedState.globalTempViewManager.database =>
val plan = sessionState.catalog.getGlobalTempView(tableIdent.identifier).getOrElse {
throw new NoSuchTableException(db = db, table = tableIdent.identifier)
}
analyzeColumnInTempView(plan, sparkSession)
case Some(_) =>
analyzeColumnInCatalog(sparkSession)
case None =>
sessionState.catalog.getTempView(tableIdent.identifier) match {
case Some(tempView) => analyzeColumnInTempView(tempView, sparkSession)
case _ => analyzeColumnInCatalog(sparkSession)
}
}

if (!analyzeColumnInCachedData(plan, sparkSession)) {
val catalog = sparkSession.sessionState.catalog
val db = tableIdent.database.getOrElse(catalog.getCurrentDatabase)
throw new NoSuchTableException(db = db, table = tableIdent.identifier)
throw new AnalysisException(
s"Temporary view $tableIdent is not cached for analyzing columns.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message looks clearer.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ class StatisticsCollectionSuite extends StatisticsCollectionTestBase with Shared
val errMsg = intercept[AnalysisException] {
sql("ANALYZE TABLE tempView COMPUTE STATISTICS FOR COLUMNS id")
}.getMessage
assert(errMsg.contains(s"Table or view 'tempView' not found in database 'default'"))
assert(errMsg.contains("Temporary view `tempView` is not cached for analyzing columns"))

// Cache the view then analyze it
sql("CACHE TABLE tempView")
Expand All @@ -548,7 +548,8 @@ class StatisticsCollectionSuite extends StatisticsCollectionTestBase with Shared
val errMsg2 = intercept[AnalysisException] {
sql(s"ANALYZE TABLE $globalTempDB.gTempView COMPUTE STATISTICS FOR COLUMNS id")
}.getMessage
assert(errMsg2.contains(s"Table or view 'gTempView' not found in database '$globalTempDB'"))
assert(errMsg2.contains(
s"Temporary view `$globalTempDB`.`gTempView` is not cached for analyzing columns"))

// Cache the view then analyze it
sql(s"CACHE TABLE $globalTempDB.gTempView")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils {
sql(s"ANALYZE TABLE $viewName COMPUTE STATISTICS")
}.getMessage
assert(e5.contains(s"$viewName is a temp view not table or permanent view"))
assertNoSuchTable(s"ANALYZE TABLE $viewName COMPUTE STATISTICS FOR COLUMNS id")
val e6 = intercept[AnalysisException] {
sql(s"ANALYZE TABLE $viewName COMPUTE STATISTICS FOR COLUMNS id")
}.getMessage
assert(e6.contains(s"Temporary view `$viewName` is not cached for analyzing columns."))
}
}

Expand Down