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 2025/03/14 06:56:20 UTC

(spark-connect-swift) branch main updated: [SPARK-51510] Add SQL-file based `SQLTests` suite

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 6c90a7e  [SPARK-51510] Add SQL-file based `SQLTests` suite
6c90a7e is described below

commit 6c90a7edd6a6bdc76a1da9ab7a639c8fc35bbe9c
Author: Dongjoon Hyun <do...@apache.org>
AuthorDate: Thu Mar 13 23:56:12 2025 -0700

    [SPARK-51510] Add SQL-file based `SQLTests` suite
    
    ### What changes were proposed in this pull request?
    
    This PR aims to add `SQL-file` based `SQLTests` suite as a new test framework. For example,
    
    - `pipesyntax.sql`
    ```sql
    VALUES (0), (1) tab(col)
    |> EXTEND col * 2 AS result
    ```
    
    - `pipesyntax.sql.json`
    ```json
    [["0","0"],["1","2"]]
    ```
    
    ### Why are the changes needed?
    
    This framework helps us improve test coverage by adding SQL file and golden answer files.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Manual test against `Apache Spark 4.0.0 RC2` and pass the CIs.
    
    ```
    $ swift test --filter SQLTests
    ...
    􀟈  Suite SQLTests started.
    􀟈  Test runAll() started.
    pipesyntax.sql
    select.sql
    􁁛  Test runAll() passed after 0.083 seconds.
    􁁛  Suite SQLTests passed after 0.083 seconds.
    􁁛  Test run with 1 test passed after 0.083 seconds.
    ```
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No.
    
    Closes #18 from dongjoon-hyun/SPARK-51510.
    
    Authored-by: Dongjoon Hyun <do...@apache.org>
    Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
 .github/.licenserc.yaml                            |  1 +
 Package.swift                                      |  5 ++-
 .../Resources/queries/pipesyntax.sql               |  2 +
 .../Resources/queries/pipesyntax.sql.json          |  1 +
 .../SparkConnectTests/Resources/queries/select.sql |  1 +
 .../Resources/queries/select.sql.json              |  1 +
 Tests/SparkConnectTests/SQLTests.swift             | 48 ++++++++++++++++++++++
 7 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/.github/.licenserc.yaml b/.github/.licenserc.yaml
index 27bf15a..5f08a50 100644
--- a/.github/.licenserc.yaml
+++ b/.github/.licenserc.yaml
@@ -16,5 +16,6 @@ header:
     - '.nojekyll'
     - 'Package.swift'
     - '**/*pb.swift'
+    - 'Tests/SparkConnectTests/Resources/queries/**'
 
   comment: on-failure
diff --git a/Package.swift b/Package.swift
index 58aa421..7f3074a 100644
--- a/Package.swift
+++ b/Package.swift
@@ -53,7 +53,10 @@ let package = Package(
     ),
     .testTarget(
       name: "SparkConnectTests",
-      dependencies: ["SparkConnect"]
+      dependencies: ["SparkConnect"],
+      resources: [
+        .copy("Resources/queries")
+      ]
     ),
   ]
 )
diff --git a/Tests/SparkConnectTests/Resources/queries/pipesyntax.sql b/Tests/SparkConnectTests/Resources/queries/pipesyntax.sql
new file mode 100644
index 0000000..cc057cb
--- /dev/null
+++ b/Tests/SparkConnectTests/Resources/queries/pipesyntax.sql
@@ -0,0 +1,2 @@
+VALUES (0), (1) tab(col)
+|> EXTEND col * 2 AS result
diff --git a/Tests/SparkConnectTests/Resources/queries/pipesyntax.sql.json b/Tests/SparkConnectTests/Resources/queries/pipesyntax.sql.json
new file mode 100644
index 0000000..bfa3b54
--- /dev/null
+++ b/Tests/SparkConnectTests/Resources/queries/pipesyntax.sql.json
@@ -0,0 +1 @@
+[["0","0"],["1","2"]]
diff --git a/Tests/SparkConnectTests/Resources/queries/select.sql b/Tests/SparkConnectTests/Resources/queries/select.sql
new file mode 100644
index 0000000..2e3761f
--- /dev/null
+++ b/Tests/SparkConnectTests/Resources/queries/select.sql
@@ -0,0 +1 @@
+SELECT 1
diff --git a/Tests/SparkConnectTests/Resources/queries/select.sql.json b/Tests/SparkConnectTests/Resources/queries/select.sql.json
new file mode 100644
index 0000000..0a0ab46
--- /dev/null
+++ b/Tests/SparkConnectTests/Resources/queries/select.sql.json
@@ -0,0 +1 @@
+[["1"]]
diff --git a/Tests/SparkConnectTests/SQLTests.swift b/Tests/SparkConnectTests/SQLTests.swift
new file mode 100644
index 0000000..3ed3568
--- /dev/null
+++ b/Tests/SparkConnectTests/SQLTests.swift
@@ -0,0 +1,48 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+import Foundation
+import Testing
+
+@testable import SparkConnect
+
+/// A test suite for various SQL statements.
+struct SQLTests {
+  let fm = FileManager.default
+  let path = Bundle.module.path(forResource: "queries", ofType: "")!
+  let encoder = JSONEncoder()
+
+#if !os(Linux)
+  @Test
+  func runAll() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    for name in try! fm.contentsOfDirectory(atPath: path).sorted() {
+      guard name.hasSuffix(".sql") else { continue }
+      print(name)
+
+      let sql = try String(contentsOf: URL(fileURLWithPath: "\(path)/\(name)"), encoding: .utf8)
+      let jsonData = try encoder.encode(try await spark.sql(sql).collect())
+      let answer = String(data: jsonData, encoding: .utf8)!
+      let expected = try String(contentsOf: URL(fileURLWithPath: "\(path)/\(name).json"), encoding: .utf8)
+      #expect(answer == expected.trimmingCharacters(in: .whitespacesAndNewlines))
+    }
+    await spark.stop()
+  }
+#endif
+}


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