wangyum commented on a change in pull request #24715: [SPARK-25474][SQL] Data source tables support fallback to HDFS for size estimation URL: https://github.com/apache/spark/pull/24715#discussion_r299268577
########## File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala ########## @@ -619,3 +620,43 @@ object DataSourceStrategy { (nonconvertiblePredicates ++ unhandledPredicates, pushedFilters, handledFilters) } } + + +/** + * Support for recalculating table statistics if table statistics are not available. + */ +class DetermineTableStats(session: SparkSession) extends Rule[LogicalPlan] { + def getHdfsSize(catalogTable: CatalogTable): Long = { + try { + val hadoopConf = session.sessionState.newHadoopConf() + val tablePath = new Path(catalogTable.location) + val fs: FileSystem = tablePath.getFileSystem(hadoopConf) + fs.getContentSummary(tablePath).getLength + } catch { + case e: IOException => + logWarning("Failed to get table size from hdfs.", e) + session.sessionState.conf.defaultSizeInBytes + } + } + + override def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { + case logical @ LogicalRelation(relation, _, Some(table), _) + if session.sessionState.conf.fallBackToHdfsForStatsEnabled && + session.sessionState.conf.manageFilesourcePartitions && table.stats.isEmpty && + table.tracksPartitionsInCatalog && table.partitionColumnNames.nonEmpty => + val withStats = Review comment: Recalculated only when `fallBackToHdfsForStatsEnabled` and `useCatalogFileIndex`: https://github.com/apache/spark/blob/c30b5297bc607ae33cc2fcf624b127942154e559/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSource.scala#L379-L388 ---------------------------------------------------------------- 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