|
| 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 | +#if !os(Linux) |
| 32 | + @Test |
| 33 | + func runAll() async throws { |
| 34 | + let spark = try await SparkSession.builder.getOrCreate() |
| 35 | + for name in try! fm.contentsOfDirectory(atPath: path).sorted() { |
| 36 | + guard name.hasSuffix(".sql") else { continue } |
| 37 | + print(name) |
| 38 | + |
| 39 | + let sql = try String(contentsOf: URL(fileURLWithPath: "\(path)/\(name)"), encoding: .utf8) |
| 40 | + let jsonData = try encoder.encode(try await spark.sql(sql).collect()) |
| 41 | + let answer = String(data: jsonData, encoding: .utf8)! |
| 42 | + let expected = try String(contentsOf: URL(fileURLWithPath: "\(path)/\(name).json"), encoding: .utf8) |
| 43 | + #expect(answer == expected.trimmingCharacters(in: .whitespacesAndNewlines)) |
| 44 | + } |
| 45 | + await spark.stop() |
| 46 | + } |
| 47 | +#endif |
| 48 | +} |
0 commit comments