You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by do...@apache.org on 2026/04/09 17:57:50 UTC

(spark-connect-swift) branch main updated: [SPARK-56420] Introduce `toExpression` method to deduplicate literal conversions

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

dongjoon 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 4de7d39  [SPARK-56420] Introduce `toExpression` method to deduplicate literal conversions
4de7d39 is described below

commit 4de7d391530f1ee332c22fda108a68b4aa4959b7
Author: Dongjoon Hyun <do...@apache.org>
AuthorDate: Thu Apr 9 10:57:43 2026 -0700

    [SPARK-56420] Introduce `toExpression` method to deduplicate literal conversions
    
    ### What changes were proposed in this pull request?
    
    This PR extracts a common `toExpression(_ value: Sendable) -> Spark_Connect_Expression` helper method to deduplicate the identical `Sendable` → `ExpressionLiteral` switch statements in `toSparkConnectPlan(_ posArguments:)` and `toSparkConnectPlan(_ namedArguments:)`.
    
    ### Why are the changes needed?
    
    The two `toSparkConnectPlan` overloads in `Extension.swift` contained identical 15-line switch statements for converting `Sendable` values to `ExpressionLiteral`. Extracting this into a shared private helper improves maintainability and reduces the risk of the two copies diverging in future changes.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Pass the CIs.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (Claude Opus 4.6)
    
    Closes #349 from dongjoon-hyun/SPARK-56420.
    
    Authored-by: Dongjoon Hyun <do...@apache.org>
    Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
 Sources/SparkConnect/Extension.swift | 75 +++++++++++++-----------------------
 1 file changed, 27 insertions(+), 48 deletions(-)

diff --git a/Sources/SparkConnect/Extension.swift b/Sources/SparkConnect/Extension.swift
index 29c40fd..92d3b2b 100644
--- a/Sources/SparkConnect/Extension.swift
+++ b/Sources/SparkConnect/Extension.swift
@@ -35,33 +35,35 @@ extension String {
     return plan
   }
 
+  private func toExpression(_ value: Sendable) -> Spark_Connect_Expression {
+    var literal = ExpressionLiteral()
+    switch value {
+    case let value as Bool:
+      literal.boolean = value
+    case let value as Int8:
+      literal.byte = Int32(value)
+    case let value as Int16:
+      literal.short = Int32(value)
+    case let value as Int32:
+      literal.integer = value
+    case let value as Int64:
+      literal.long = value
+    case let value as Int:
+      literal.long = Int64(value)
+    case let value as String:
+      literal.string = value
+    default:
+      literal.string = value as! String
+    }
+    var expr = Spark_Connect_Expression()
+    expr.literal = literal
+    return expr
+  }
+
   func toSparkConnectPlan(_ posArguments: [Sendable]) -> Plan {
     var sql = Spark_Connect_SQL()
     sql.query = self
-    sql.posArguments = posArguments.map {
-      var literal = ExpressionLiteral()
-      switch $0 {
-      case let value as Bool:
-        literal.boolean = value
-      case let value as Int8:
-        literal.byte = Int32(value)
-      case let value as Int16:
-        literal.short = Int32(value)
-      case let value as Int32:
-        literal.integer = value
-      case let value as Int64:
-        literal.long = value
-      case let value as Int:
-        literal.long = Int64(value)
-      case let value as String:
-        literal.string = value
-      default:
-        literal.string = $0 as! String
-      }
-      var expr = Spark_Connect_Expression()
-      expr.literal = literal
-      return expr
-    }
+    sql.posArguments = posArguments.map { toExpression($0) }
     var relation = Relation()
     relation.sql = sql
     var plan = Plan()
@@ -72,30 +74,7 @@ extension String {
   func toSparkConnectPlan(_ namedArguments: [String: Sendable]) -> Plan {
     var sql = Spark_Connect_SQL()
     sql.query = self
-    sql.namedArguments = namedArguments.mapValues { value in
-      var literal = ExpressionLiteral()
-      switch value {
-      case let value as Bool:
-        literal.boolean = value
-      case let value as Int8:
-        literal.byte = Int32(value)
-      case let value as Int16:
-        literal.short = Int32(value)
-      case let value as Int32:
-        literal.integer = value
-      case let value as Int64:
-        literal.long = value
-      case let value as Int:
-        literal.long = Int64(value)
-      case let value as String:
-        literal.string = value
-      default:
-        literal.string = value as! String
-      }
-      var expr = Spark_Connect_Expression()
-      expr.literal = literal
-      return expr
-    }
+    sql.namedArguments = namedArguments.mapValues { toExpression($0) }
     var relation = Relation()
     relation.sql = sql
     var plan = Plan()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org