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 a8ba93e97e [spark] Fix merge into table with varchar type (#6192)
a8ba93e97e is described below

commit a8ba93e97eaaa2a46220c314b4c542959932d0b9
Author: Zouxxyy <zouxinyu....@alibaba-inc.com>
AuthorDate: Wed Sep 3 21:30:17 2025 +0800

    [spark] Fix merge into table with varchar type (#6192)
---
 .../paimon/spark/commands/MergeIntoPaimonTable.scala   |  4 +---
 .../paimon/spark/sql/MergeIntoTableTestBase.scala      | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git 
a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/MergeIntoPaimonTable.scala
 
b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/MergeIntoPaimonTable.scala
index 3697b4c695..3e8d4deabe 100644
--- 
a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/MergeIntoPaimonTable.scala
+++ 
b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/MergeIntoPaimonTable.scala
@@ -58,8 +58,6 @@ case class MergeIntoPaimonTable(
 
   lazy val relation: DataSourceV2Relation = 
PaimonRelation.getPaimonRelation(targetTable)
 
-  lazy val tableSchema: StructType = v2Table.schema
-
   private lazy val (targetOnlyCondition, filteredTargetPlan): 
(Option[Expression], LogicalPlan) = {
     val filtersOnlyTarget = getExpressionOnlyRelated(mergeCondition, 
targetTable)
     (
@@ -281,7 +279,7 @@ case class MergeIntoPaimonTable(
     val matchedOutputs = processMergeActions(matchedActions)
     val notMatchedBySourceOutputs = 
processMergeActions(notMatchedBySourceActions)
     val notMatchedOutputs = processMergeActions(notMatchedActions)
-    val outputFields = mutable.ArrayBuffer(tableSchema.fields: _*)
+    val outputFields = mutable.ArrayBuffer(targetTable.schema.fields: _*)
     if (writeRowLineage) {
       outputFields += PaimonMetadataColumn.ROW_ID.toStructField
       outputFields += PaimonMetadataColumn.SEQUENCE_NUMBER.toStructField
diff --git 
a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/MergeIntoTableTestBase.scala
 
b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/MergeIntoTableTestBase.scala
index f7e1f73afb..4564e1646c 100644
--- 
a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/MergeIntoTableTestBase.scala
+++ 
b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/MergeIntoTableTestBase.scala
@@ -653,6 +653,24 @@ abstract class MergeIntoTableTestBase extends 
PaimonSparkTestBase with PaimonTab
       )
     }
   }
+
+  test(s"Paimon MergeInto: merge into with varchar") {
+    withTable("source", "target") {
+      createTable("source", "a INT, b VARCHAR(32)", Seq("a"))
+      createTable("target", "a INT, b VARCHAR(32)", Seq("a"))
+      sql("INSERT INTO target values (1, 'Alice'), (2, 'Bob')")
+      sql("INSERT INTO source values (1, 'Eve'), (3, 'Cat')")
+
+      sql(s"""
+             |MERGE INTO target
+             |USING source
+             |ON target.a = source.a
+             |WHEN MATCHED THEN
+             |UPDATE SET a = source.a, b = source.b
+             |""".stripMargin)
+      checkAnswer(sql("SELECT * FROM target ORDER BY a, b"), Seq(Row(1, 
"Eve"), Row(2, "Bob")))
+    }
+  }
 }
 
 trait MergeIntoPrimaryKeyTableTest extends PaimonSparkTestBase with 
PaimonPrimaryKeyTable {

Reply via email to