This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new a2b2338cc6 [spark] Fix mergedRecordSize truncation to zero (#8965)
a2b2338cc6 is described below

commit a2b2338cc630a9b69e1b83c30197515bd3e14cf8
Author: cxzl25 <[email protected]>
AuthorDate: Mon Aug 3 19:04:56 2026 +0800

    [spark] Fix mergedRecordSize truncation to zero (#8965)
---
 .../commands/PaimonAnalyzeTableColumnCommand.scala   |  2 +-
 .../paimon/spark/sql/AnalyzeTableTestBase.scala      | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git 
a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/PaimonAnalyzeTableColumnCommand.scala
 
b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/PaimonAnalyzeTableColumnCommand.scala
index 412224b0bf..6f73c31157 100644
--- 
a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/PaimonAnalyzeTableColumnCommand.scala
+++ 
b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/PaimonAnalyzeTableColumnCommand.scala
@@ -70,7 +70,7 @@ case class PaimonAnalyzeTableColumnCommand(
 
     val totalRecordCount = currentSnapshot.totalRecordCount()
     checkState(totalRecordCount >= mergedRecordCount)
-    val mergedRecordSize = totalSize * (mergedRecordCount.toDouble / 
totalRecordCount).toLong
+    val mergedRecordSize = (totalSize.toDouble * mergedRecordCount / 
totalRecordCount).toLong
 
     // convert to paimon stats
     val tableSchema = table.schema()
diff --git 
a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/AnalyzeTableTestBase.scala
 
b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/AnalyzeTableTestBase.scala
index c6860779cd..34c38062f0 100644
--- 
a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/AnalyzeTableTestBase.scala
+++ 
b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/AnalyzeTableTestBase.scala
@@ -52,6 +52,26 @@ abstract class AnalyzeTableTestBase extends 
PaimonSparkTestBase {
     Assertions.assertTrue(stats.colStats().isEmpty)
   }
 
+  test("Paimon analyze: mergedRecordSize should not truncate to zero") {
+    spark.sql(s"""
+                 |CREATE TABLE T (id STRING, name STRING)
+                 |USING PAIMON
+                 |TBLPROPERTIES ('primary-key'='id')
+                 |""".stripMargin)
+
+    spark.sql(s"INSERT INTO T VALUES ('1', 'a')")
+    spark.sql(s"INSERT INTO T VALUES ('1', 'bb')")
+    spark.sql(s"INSERT INTO T VALUES ('1', 'ccc')")
+
+    spark.sql(s"ANALYZE TABLE T COMPUTE STATISTICS")
+
+    val stats = loadTable("T").statistics().get()
+    Assertions.assertEquals(1L, stats.mergedRecordCount().getAsLong)
+
+    Assertions.assertTrue(stats.mergedRecordSize().isPresent)
+    Assertions.assertTrue(stats.mergedRecordSize().getAsLong > 0)
+  }
+
   test("Paimon analyze: test statistic system table") {
     spark.sql(s"""
                  |CREATE TABLE T (id STRING, name STRING, i INT, l LONG)

Reply via email to