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

dongjoon-hyun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/spark-connect-swift.git


The following commit(s) were added to refs/heads/main by this push:
     new be871bb  [SPARK-60053] Fix `MergeIntoWriter.update` to pass 
assignments to the merge action
be871bb is described below

commit be871bbc269b9c081d58e02442994ed5557b05a2
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Wed Oct 7 13:44:10 2026 -0700

    [SPARK-60053] Fix `MergeIntoWriter.update` to pass assignments to the merge 
action
    
    ### What changes were proposed in this pull request?
    
    This PR aims to fix `MergeIntoWriter.update` to pass the given column 
assignments (`map`) to `buildMergeAction`.
    
    ### Why are the changes needed?
    
    Previously, `update(_:_:_:)` called `buildMergeAction(ActionType.update, 
condition)` without `map`, so `assignments` silently defaulted to `[:]`. As a 
result, the `UPDATE` merge action was sent to the server without any 
assignments, and `whenMatched().update(map:)` and 
`whenNotMatchedBySource().update(map:)` ignored the user-provided assignments. 
In contrast, `insert(_:_:)` passes `map` correctly.
    
    ```swift
    await mergeInto.whenMatched().update(map: ["t.v": "s.v"])  // assignments 
were dropped
    ```
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes. `whenMatched().update(map:)` and 
`whenNotMatchedBySource().update(map:)` now send the given column assignments 
as intended.
    
    ### How was this patch tested?
    
    Pass the CIs with the newly added test case, 
`MergeIntoWriterTests.updateAssignments`. It checks the built 
`MergeIntoTableCommand` and does not need a Spark Connect server.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Opus 5.5
    
    Closes #584 from dongjoon-hyun/SPARK-60053.
    
    Authored-by: Dongjoon Hyun <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 Sources/SparkConnect/MergeIntoWriter.swift         |  3 ++-
 Tests/SparkConnectTests/MergeIntoWriterTests.swift | 23 +++++++++++++++++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/Sources/SparkConnect/MergeIntoWriter.swift 
b/Sources/SparkConnect/MergeIntoWriter.swift
index 10f09f3..ee236cc 100644
--- a/Sources/SparkConnect/MergeIntoWriter.swift
+++ b/Sources/SparkConnect/MergeIntoWriter.swift
@@ -216,7 +216,8 @@ public actor MergeIntoWriter {
   public func update(_ condition: String?, _ map: [String: String], _ 
notMatchedBySource: Bool)
     -> MergeIntoWriter
   {
-    appendUpdateDeleteAction(buildMergeAction(ActionType.update, condition), 
notMatchedBySource)
+    appendUpdateDeleteAction(
+      buildMergeAction(ActionType.update, condition, map), notMatchedBySource)
   }
 
   public func delete(_ condition: String?, _ notMatchedBySource: Bool) -> 
MergeIntoWriter {
diff --git a/Tests/SparkConnectTests/MergeIntoWriterTests.swift 
b/Tests/SparkConnectTests/MergeIntoWriterTests.swift
index 8bd319e..4ebfe97 100644
--- a/Tests/SparkConnectTests/MergeIntoWriterTests.swift
+++ b/Tests/SparkConnectTests/MergeIntoWriterTests.swift
@@ -22,9 +22,10 @@ import FoundationEssentials
 #else
 import Foundation
 #endif
-import SparkConnect
 import Testing
 
+@testable import SparkConnect
+
 /// A test suite for `MergeIntoWriter`
 /// Since this requires Apache Spark 4 with Iceberg support (SPARK-48794), 
this suite only tests syntaxes.
 @Suite(.serialized)
@@ -103,4 +104,24 @@ struct MergeIntoWriterTests {
     })
     await spark.stop()
   }
+
+  @Test
+  func updateAssignments() async throws {
+    let spark = try SparkSession("sc://localhost")
+    let mergeInto = try await spark.range(1).mergeInto("t", "true")
+    _ = await mergeInto.whenMatched().update(map: ["t.v": "s.v"])
+    _ = await mergeInto.whenNotMatchedBySource("t.v > 0").update(map: ["t.v": 
"0"])
+    let command = await mergeInto.mergeIntoTableCommand
+    #expect(command.matchActions.count == 1)
+    #expect(command.notMatchedBySourceActions.count == 1)
+    for (action, value) in [
+      (command.matchActions[0].mergeAction, "s.v"),
+      (command.notMatchedBySourceActions[0].mergeAction, "0"),
+    ] {
+      #expect(action.actionType == .update)
+      #expect(action.assignments.count == 1)
+      #expect(action.assignments.first?.key.expressionString.expression == 
"t.v")
+      #expect(action.assignments.first?.value.expressionString.expression == 
value)
+    }
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to