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 8cb27d7ec1 [spark] Support options_map in compact procedure (#11239)
8cb27d7ec1 is described below

commit 8cb27d7ec11e34007c7a1459d89c323277708ba0
Author: LsomeYeah <[email protected]>
AuthorDate: Thu Nov 19 11:58:40 2026 +0800

    [spark] Support options_map in compact procedure (#11239)
---
 docs/docs/spark/procedures/maintenance.md          | 10 ++++++++
 .../spark/procedure/CompactDatabaseProcedure.java  |  5 ++--
 .../paimon/spark/procedure/CompactProcedure.java   | 11 ++++++++
 .../spark/procedure/CompactProcedureTestBase.scala | 30 +++++++++++++++++++++-
 4 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/docs/docs/spark/procedures/maintenance.md 
b/docs/docs/spark/procedures/maintenance.md
index 2153d68247..add880bdef 100644
--- a/docs/docs/spark/procedures/maintenance.md
+++ b/docs/docs/spark/procedures/maintenance.md
@@ -44,6 +44,7 @@ Compact files.
 - `partition_idle_time` (`STRING`, optional): this is used to do a full 
compaction for partition which had not received any new data for 
'partition_idle_time'. And only these partitions will be compacted. This 
argument can not be used with order compact.
 - `compact_strategy` (`STRING`, optional): `full` selects all candidate files 
in the chosen scope; `minor` selects files according to the compaction policy. 
Defaults to `minor` when incremental clustering is enabled, otherwise `full`.
 - `buckets` (`STRING`, optional): fixed-bucket IDs, comma-separated IDs, or 
inclusive ranges, for example `'0-3,7'`. Omit to include all buckets. Valid 
only for fixed-bucket tables without sort compaction.
+- `options_map` (`MAP<STRING, STRING>`, optional): additional dynamic table 
options, including values containing commas. Options are applied in the order 
`options`, then `options_map`, so map entries override matching keys in 
`options`. Both apply only to this invocation and do not modify stored table 
properties. This argument is appended after `buckets` for positional calls.
 
 ```sql
 SET spark.sql.shuffle.partitions=10; --set the compact parallelism
@@ -66,6 +67,15 @@ CALL sys.compact(table => 'T', compact_strategy => 'minor');
 
 -- Limit full compaction to these buckets of a fixed-bucket table with at 
least 8 buckets.
 CALL sys.compact(table => 'T', compact_strategy => 'full', buckets => '0-3,7');
+
+-- Pass comma-containing values without splitting them into separate options.
+CALL sys.compact(
+  table => 'T',
+  options => 'file.format.per.level=0:orc',
+  options_map => map(
+    'file.format.per.level', '0:avro,1:parquet'
+  )
+);
 ```
 
 ## compact_database
diff --git 
a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/CompactDatabaseProcedure.java
 
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/CompactDatabaseProcedure.java
index a68eee65dd..cfa816cf9e 100644
--- 
a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/CompactDatabaseProcedure.java
+++ 
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/CompactDatabaseProcedure.java
@@ -181,7 +181,7 @@ public class CompactDatabaseProcedure extends BaseProcedure 
{
 
         // Create InternalRow with the parameters for CompactProcedure
         // Parameters: table, partitions, compact_strategy, order_strategy, 
order_by, where,
-        // options, partition_idle_time, buckets
+        // options, partition_idle_time, buckets, options_map
         InternalRow compactArgs =
                 newInternalRow(
                         UTF8String.fromString(tableName), // table
@@ -192,7 +192,8 @@ public class CompactDatabaseProcedure extends BaseProcedure 
{
                         null, // where
                         options == null ? null : 
UTF8String.fromString(options), // options
                         null, // partition_idle_time
-                        null // buckets
+                        null, // buckets
+                        null // options_map
                         );
 
         InternalRow[] result = compactProcedure.call(compactArgs);
diff --git 
a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/CompactProcedure.java
 
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/CompactProcedure.java
index bdcacedbda..5b02778be6 100644
--- 
a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/CompactProcedure.java
+++ 
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/CompactProcedure.java
@@ -72,6 +72,7 @@ import org.apache.spark.sql.PaimonUtils;
 import org.apache.spark.sql.Row;
 import org.apache.spark.sql.SparkSession;
 import org.apache.spark.sql.catalyst.InternalRow;
+import org.apache.spark.sql.catalyst.util.MapData;
 import org.apache.spark.sql.connector.catalog.Identifier;
 import org.apache.spark.sql.connector.catalog.TableCatalog;
 import org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation;
@@ -144,6 +145,8 @@ public class CompactProcedure extends BaseProcedure {
                 ProcedureParameter.optional("options", StringType),
                 ProcedureParameter.optional("partition_idle_time", StringType),
                 ProcedureParameter.optional("buckets", StringType),
+                ProcedureParameter.optional(
+                        "options_map", DataTypes.createMapType(StringType, 
StringType)),
             };
 
     private static final StructType OUTPUT_TYPE =
@@ -184,6 +187,7 @@ public class CompactProcedure extends BaseProcedure {
         Duration partitionIdleTime =
                 blank(args, 7) ? null : 
TimeUtils.parseDuration(args.getString(7));
         String buckets = blank(args, 8) ? null : args.getString(8);
+        MapData optionsMap = args.isNullAt(9) ? null : args.getMap(9);
         if (OrderType.NONE.name().equals(sortType) && !sortColumns.isEmpty()) {
             throw new IllegalArgumentException(
                     "order_strategy \"none\" cannot work with order_by 
columns.");
@@ -235,6 +239,13 @@ public class CompactProcedure extends BaseProcedure {
                     ProcedureUtils.putIfNotEmpty(
                             dynamicOptions, CoreOptions.WRITE_ONLY.key(), 
"false");
                     ProcedureUtils.putAllOptions(dynamicOptions, options);
+                    if (optionsMap != null) {
+                        for (int i = 0; i < optionsMap.numElements(); i++) {
+                            dynamicOptions.put(
+                                    
optionsMap.keyArray().getUTF8String(i).toString(),
+                                    
optionsMap.valueArray().getUTF8String(i).toString());
+                        }
+                    }
                     table = table.copy(dynamicOptions);
                     if (coreOptions.clusteringIncrementalEnabled()
                             && (!OrderType.NONE.name().equals(sortType))) {
diff --git 
a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/procedure/CompactProcedureTestBase.scala
 
b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/procedure/CompactProcedureTestBase.scala
index de5b2c0858..8671762798 100644
--- 
a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/procedure/CompactProcedureTestBase.scala
+++ 
b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/procedure/CompactProcedureTestBase.scala
@@ -18,7 +18,7 @@
 
 package org.apache.paimon.spark.procedure
 
-import org.apache.paimon.Snapshot
+import org.apache.paimon.{CoreOptions, Snapshot}
 import org.apache.paimon.Snapshot.CommitKind
 import org.apache.paimon.append.dataevolution.DataEvolutionNormalCompactTask
 import org.apache.paimon.data.BinaryRow
@@ -490,6 +490,34 @@ abstract class CompactProcedureTestBase extends 
PaimonSparkTestBase with StreamT
       })
   }
 
+  test("Paimon Procedure: compact options_map preserves commas and overrides 
options") {
+    withTable("T") {
+      spark.sql("""
+                  |CREATE TABLE T (id INT, value STRING)
+                  |TBLPROPERTIES ('primary-key'='id', 'bucket'='1',
+                  |  'write-only'='true', 'num-levels'='2')
+                  |""".stripMargin)
+      spark.sql("INSERT INTO T VALUES (1, 'a')")
+      spark.sql("INSERT INTO T VALUES (2, 'b')")
+      val table = loadTable("T")
+      val schemaManager = table.schemaManager()
+      val storedOptions = schemaManager.latest().get().options().asScala.toMap
+      val formatKey = CoreOptions.FILE_FORMAT_PER_LEVEL.key()
+
+      checkAnswer(
+        spark.sql(
+          s"CALL sys.compact(table => 'T', options => '$formatKey=0:orc', " +
+            s"options_map => map('$formatKey', '0:avro,1:avro'))"),
+        Seq(Row(true)))
+
+      val files = 
table.newSnapshotReader.read.dataSplits.asScala.flatMap(_.dataFiles.asScala)
+      assert(files.nonEmpty)
+      assert(files.forall(file => file.level() == 1 && 
file.fileName().endsWith(".avro")))
+      checkAnswer(spark.sql("SELECT * FROM T"), Seq(Row(1, "a"), Row(2, "b")))
+      assert(schemaManager.latest().get().options().asScala.toMap == 
storedOptions)
+    }
+  }
+
   test("Paimon Procedure: compact specified bucket ranges") {
     withTable("T") {
       spark.sql("""

Reply via email to