@@ -13,3 +13,82 @@ So far, this library project is tracking the upstream changes like the [Apache S
1313- [ gRPC Swift Protobuf 1.0 (March 2025)] ( https://github.com/grpc/grpc-swift-protobuf/releases/tag/1.1.0 )
1414- [ gRPC Swift NIO Transport 1.0 (March 2025)] ( https://github.com/grpc/grpc-swift-nio-transport/releases/tag/1.0.1 )
1515- [ Apache Arrow Swift] ( https://github.com/apache/arrow/tree/main/swift )
16+
17+ ## How to use in your apps
18+
19+ Create a Swift project.
20+ ```
21+ $ mkdir SparkConnectSwiftApp
22+ $ cd SparkConnectSwiftApp
23+ $ swift package init --name SparkConnectSwiftApp --type executable
24+ ```
25+
26+ Add ` SparkConnect ` package to the dependency like the following
27+ ```
28+ $ cat Package.swift
29+ import PackageDescription
30+
31+ let package = Package(
32+ name: "SparkConnectSwiftApp",
33+ platforms: [
34+ .macOS(.v15)
35+ ],
36+ dependencies: [
37+ .package(url: "https://github.com/apache/spark-connect-swift.git", branch: "main")
38+ ],
39+ targets: [
40+ .executableTarget(
41+ name: "SparkConnectSwiftApp",
42+ dependencies: [.product(name: "SparkConnect", package: "spark-connect-swift")]
43+ )
44+ ]
45+ )
46+ ```
47+
48+ Use ` SparkSession ` of ` SparkConnect ` module in Swift.
49+
50+ ```
51+ $ cat Sources/main.swift
52+
53+ import SparkConnect
54+
55+ let spark = try await SparkSession.builder.getOrCreate()
56+ print("Connected to Apache Spark \(await spark.version) Server")
57+
58+ let statements = [
59+ "DROP TABLE IF EXISTS t",
60+ "CREATE TABLE IF NOT EXISTS t(a INT)",
61+ "INSERT INTO t VALUES (1), (2), (3)",
62+ ]
63+
64+ for s in statements {
65+ print("EXECUTE: \(s)")
66+ _ = try await spark.sql(s).count()
67+ }
68+ print("SELECT * FROM t")
69+ try await spark.sql("SELECT * FROM t").show()
70+
71+ await spark.stop()
72+ ```
73+
74+ Run your Swift application.
75+
76+ ```
77+ $ swift run
78+ ...
79+ Connected to Apache Spark 4.0.0 Server
80+ EXECUTE: DROP TABLE IF EXISTS t
81+ EXECUTE: CREATE TABLE IF NOT EXISTS t(a INT)
82+ EXECUTE: INSERT INTO t VALUES (1), (2), (3)
83+ SELECT * FROM t
84+ +---+
85+ | a |
86+ +---+
87+ | 2 |
88+ | 1 |
89+ | 3 |
90+ +---+
91+ ```
92+
93+ You can find this example in the following repository.
94+ - https://github.com/dongjoon-hyun/spark-connect-swift-app
0 commit comments