You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/05/10 05:54:44 UTC

[GitHub] [spark] qiuliang988 commented on a diff in pull request #36412: [SPARK-39073][SQL] Keep rowCount after hive table partition pruning if table only have hive statistics

qiuliang988 commented on code in PR #36412:
URL: https://github.com/apache/spark/pull/36412#discussion_r868841346


##########
sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/PruneHiveTablePartitions.scala:
##########
@@ -74,6 +74,32 @@ private[sql] class PruneHiveTablePartitions(session: SparkSession)
         0L
       }
     }
+    if (sizeOfPartitions.forall(_ > 0) && prunedPartitions.forall(_.stats.isDefined)) {
+      val rowCountOfPartitions = prunedPartitions.map { partition =>
+        val rowCount = partition.stats.get.rowCount.map(_.toLong)
+        if (rowCount.isDefined && rowCount.get > 0L) {
+          rowCount.get
+        } else {
+          0L
+        }
+      }
+      if (rowCountOfPartitions.forall(_ > 0)) {
+        val stats = relation.stats
+        val oldRowCount = stats.rowCount
+        val newRowCount = BigInt(rowCountOfPartitions.sum)
+        var colStats = Map.empty[String, CatalogColumnStat]
+        if (oldRowCount.isDefined) {
+          stats.attributeStats.map(_._2.updateCountStats(
+            oldNumRows = oldRowCount.get, newNumRows = newRowCount))
+          colStats = stats.attributeStats.map{ case (attr, colStat) =>
+            (attr.name, colStat.toCatalogColumnStat(attr.name, attr.dataType))}
+        }
+        return relation.tableMeta.copy(stats = Some(CatalogStatistics(
+          sizeInBytes = BigInt(sizeOfPartitions.sum),
+          rowCount = Option(newRowCount),
+          colStats = colStats)))
+      }
+    }
     if (sizeOfPartitions.forall(_ > 0)) {

Review Comment:
   @cloud-fan Thanks for your advice. I have modified the code and submitted it again



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org