|
| 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 | +import SparkConnect |
| 24 | + |
| 25 | +/// A test suite for `Apache Iceberg` integration |
| 26 | +@Suite(.serialized) |
| 27 | +struct IcebergTests { |
| 28 | + let ICEBERG_DATABASE = "local.db" |
| 29 | + let icebergEnabled = ProcessInfo.processInfo.environment["SPARK_ICEBERG_TEST_ENABLED"] != nil |
| 30 | + |
| 31 | + @Test |
| 32 | + func test() async throws { |
| 33 | + guard icebergEnabled else { return } |
| 34 | + let t1 = "\(ICEBERG_DATABASE).TABLE_" + UUID().uuidString.replacingOccurrences(of: "-", with: "") |
| 35 | + let t2 = "\(ICEBERG_DATABASE).TABLE_" + UUID().uuidString.replacingOccurrences(of: "-", with: "") |
| 36 | + |
| 37 | + let spark = try await SparkSession.builder.getOrCreate() |
| 38 | + |
| 39 | + try await SQLHelper.withTable(spark, t1, t2)({ |
| 40 | + try await spark.sql("CREATE TABLE \(t1) (id BIGINT, data STRING) USING ICEBERG").count() |
| 41 | + try await spark.sql("CREATE TABLE \(t2) (id BIGINT, data STRING) USING ICEBERG").count() |
| 42 | + |
| 43 | + #expect(try await spark.catalog.tableExists(t1)) |
| 44 | + #expect(try await spark.catalog.tableExists(t2)) |
| 45 | + |
| 46 | + #expect(try await spark.table(t1).count() == 0) |
| 47 | + #expect(try await spark.table(t2).count() == 0) |
| 48 | + |
| 49 | + try await spark.sql("INSERT INTO \(t1) VALUES (1, 'a'), (2, 'b'), (3, 'c')").count() |
| 50 | + #expect(try await spark.table(t1).count() == 3) |
| 51 | + #expect(try await spark.table(t2).count() == 0) |
| 52 | + |
| 53 | + try await spark.table(t1).writeTo(t2).append() |
| 54 | + #expect(try await spark.table(t2).count() == 3) |
| 55 | + |
| 56 | + try await spark.table(t1).writeTo(t2).append() |
| 57 | + #expect(try await spark.table(t2).count() == 6) |
| 58 | + |
| 59 | + try await spark.table(t1).writeTo(t2).replace() |
| 60 | + #expect(try await spark.table(t2).count() == 3) |
| 61 | + |
| 62 | + try await spark.table(t1).writeTo(t2).overwrite("true") |
| 63 | + #expect(try await spark.table(t2).count() == 3) |
| 64 | + |
| 65 | + try await spark.table(t1).writeTo(t2).overwrite("false") |
| 66 | + #expect(try await spark.table(t2).count() == 6) |
| 67 | + }) |
| 68 | + |
| 69 | + await spark.stop() |
| 70 | + } |
| 71 | +} |
0 commit comments