Skip to content

Commit aebb88d

Browse files
committed
[SPARK-51510] Add SQL-file based SQLTests suite
1 parent 98e9554 commit aebb88d

File tree

7 files changed

+56
-1
lines changed

7 files changed

+56
-1
lines changed

.github/.licenserc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ header:
1616
- '.nojekyll'
1717
- 'Package.swift'
1818
- '**/*pb.swift'
19+
- 'Tests/SparkConnectTests/Resources/queries/**'
1920

2021
comment: on-failure

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ let package = Package(
5353
),
5454
.testTarget(
5555
name: "SparkConnectTests",
56-
dependencies: ["SparkConnect"]
56+
dependencies: ["SparkConnect"],
57+
resources: [
58+
.copy("Resources/queries")
59+
]
5760
),
5861
]
5962
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VALUES (0), (1) tab(col)
2+
|> EXTEND col * 2 AS result
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[["0","0"],["1","2"]]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[["1"]]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
import Foundation
21+
import Testing
22+
23+
@testable import SparkConnect
24+
25+
/// A test suite for various SQL statements.
26+
struct SQLTests {
27+
let fm = FileManager.default
28+
let path = Bundle.module.path(forResource: "queries", ofType: "")!
29+
let encoder = JSONEncoder()
30+
31+
@Test
32+
func runAll() async throws {
33+
let spark = try await SparkSession.builder.getOrCreate()
34+
for name in try! fm.contentsOfDirectory(atPath: path).sorted() {
35+
guard name.hasSuffix(".sql") else { continue }
36+
print(name)
37+
38+
let sql = try String(contentsOf: URL(fileURLWithPath: "\(path)/\(name)"), encoding: .utf8)
39+
let jsonData = try encoder.encode(try await spark.sql(sql).collect())
40+
let answer = String(data: jsonData, encoding: .utf8)!
41+
let expected = try String(contentsOf: URL(fileURLWithPath: "\(path)/\(name).json"), encoding: .utf8)
42+
#expect(answer == expected.trimmingCharacters(in: .whitespacesAndNewlines))
43+
}
44+
await spark.stop()
45+
}
46+
}

0 commit comments

Comments
 (0)