This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 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 83bc1f3e67 [spark] Fix clustering strategy auto selection using wrong
column count (#7514)
83bc1f3e67 is described below
commit 83bc1f3e67fbcf33f29a9093a738a47ec38a4045
Author: Zouxxyy <[email protected]>
AuthorDate: Tue Mar 24 19:35:48 2026 +0800
[spark] Fix clustering strategy auto selection using wrong column count
(#7514)
---
.../paimon/spark/commands/PaimonSparkWriter.scala | 2 +-
.../apache/paimon/spark/sql/SparkWriteITCase.scala | 23 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git
a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/PaimonSparkWriter.scala
b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/PaimonSparkWriter.scala
index b4ba7efc09..26ca12197c 100644
---
a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/PaimonSparkWriter.scala
+++
b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/PaimonSparkWriter.scala
@@ -307,7 +307,7 @@ case class PaimonSparkWriter(
(!coreOptions.clusteringIncrementalEnabled() || coreOptions
.clusteringIncrementalOptimizeWrite()) &&
(!clusteringColumns.isEmpty)
) {
- val strategy =
coreOptions.clusteringStrategy(tableSchema.fields().size())
+ val strategy =
coreOptions.clusteringStrategy(clusteringColumns.size())
val sorter = TableSorter.getSorter(table, strategy,
clusteringColumns)
input = sorter.sort(data)
}
diff --git
a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/SparkWriteITCase.scala
b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/SparkWriteITCase.scala
index 96ada9d9eb..b2ae78f1ce 100644
---
a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/SparkWriteITCase.scala
+++
b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/SparkWriteITCase.scala
@@ -18,6 +18,7 @@
package org.apache.paimon.spark.sql
+import org.apache.paimon.CoreOptions
import org.apache.paimon.CoreOptions.BucketFunctionType
import org.apache.paimon.catalog.Identifier
import org.apache.paimon.schema.Schema
@@ -308,6 +309,28 @@ class SparkWriteITCase extends PaimonSparkTestBase {
}
}
+ test("Paimon Write: clustering strategy auto should use clustering columns
size") {
+ withTable("T") {
+ // 6 fields but only 1 clustering column -> auto should pick ORDER, not
HILBERT
+ spark.sql(s"""
+ |CREATE TABLE T (a INT, b INT, c INT, d INT, e INT, f
STRING)
+ |TBLPROPERTIES ('bucket'='-1', 'clustering.columns'='a')
+ |""".stripMargin)
+
+ val table = loadTable("T")
+ val coreOptions = new CoreOptions(table.options())
+ val clusteringColumns = coreOptions.clusteringColumns()
+ val strategy = coreOptions.clusteringStrategy(clusteringColumns.size())
+ Assertions.assertEquals(CoreOptions.OrderType.ORDER, strategy)
+
+ spark.sql("INSERT INTO T VALUES (3,1,1,1,1,'c'), (1,2,2,2,2,'a'),
(2,3,3,3,3,'b')")
+ checkAnswer(
+ spark.sql("SELECT a FROM T"),
+ Row(1) :: Row(2) :: Row(3) :: Nil
+ )
+ }
+ }
+
BucketFunctionType
.values()
.foreach(