maropu commented on a change in pull request #24200: [SPARK-27266][SQL] Support ANALYZE TABLE to collect tables stats for cached catalog views URL: https://github.com/apache/spark/pull/24200#discussion_r268959862
########## File path: sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala ########## @@ -35,19 +35,27 @@ case class AnalyzeTableCommand( val tableIdentWithDB = TableIdentifier(tableIdent.table, Some(db)) val tableMeta = sessionState.catalog.getTableMetadata(tableIdentWithDB) if (tableMeta.tableType == CatalogTableType.VIEW) { - throw new AnalysisException("ANALYZE TABLE is not supported on views.") - } - - // Compute stats for the whole table - val newTotalSize = CommandUtils.calculateTotalSize(sparkSession, tableMeta) - val newRowCount = - if (noscan) None else Some(BigInt(sparkSession.table(tableIdentWithDB).count())) - - // Update the metastore if the above statistics of the table are different from those - // recorded in the metastore. - val newStats = CommandUtils.compareAndGetNewStats(tableMeta.stats, newTotalSize, newRowCount) - if (newStats.isDefined) { - sessionState.catalog.alterTableStats(tableIdentWithDB, newStats) + // Analyzes a catalog view if the view is cached + val table = sparkSession.table(tableIdent.quotedString) + val cacheManager = sparkSession.sharedState.cacheManager + if (cacheManager.lookupCachedData(table.logicalPlan).isDefined) { + // To collect table stats, materializes an underlying columnar RDD + table.collect() Review comment: I wrote this code to do the same thing with the normal case: https://github.com/apache/spark/blob/90b72512f46ac08008d574577c65263d9b13a33c/sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala#L44 ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org