You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "dongjoon-hyun (via GitHub)" <gi...@apache.org> on 2025/03/12 06:11:16 UTC

[PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

dongjoon-hyun opened a new pull request, #10:
URL: https://github.com/apache/spark-connect-swift/pull/10

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as new features, bug fixes, or other behavior changes. Documentation-only updates are not considered user-facing changes.
   
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #10:
URL: https://github.com/apache/spark-connect-swift/pull/10#issuecomment-2716693543

   Merged to main~


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #10:
URL: https://github.com/apache/spark-connect-swift/pull/10#discussion_r1990676843


##########
Sources/SparkConnect/DataFrame.swift:
##########
@@ -0,0 +1,195 @@
+//
+// 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 Atomics
+import Foundation
+import GRPCCore
+import GRPCNIOTransportHTTP2
+import GRPCProtobuf
+import NIOCore
+import SwiftyTextTable
+import Synchronization
+
+/// A DataFrame which supports only SQL queries
+public actor DataFrame: Sendable {
+  var spark: SparkSession
+  var plan: Plan
+  var schema: DataType? = nil
+  private var batches: [RecordBatch] = [RecordBatch]()
+
+  /// Create a new `DataFrame`instance with the given Spark session and plan.
+  /// - Parameters:
+  ///   - spark: A ``SparkSession`` instance to use.
+  ///   - plan: A plan to execute.
+  init(spark: SparkSession, plan: Plan) async throws {
+    self.spark = spark
+    self.plan = plan
+  }
+
+  /// Create a new `DataFrame` instance with the given SparkSession and a SQL statement.
+  /// - Parameters:
+  ///   - spark: A `SparkSession` instance to use.
+  ///   - sqlText: A SQL statement.
+  init(spark: SparkSession, sqlText: String) async throws {
+    self.spark = spark
+    self.plan = sqlText.toSparkConnectPlan
+  }
+
+  /// Set the schema. This is used to store the analized schema response from `Spark Connect` server.
+  /// - Parameter schema: <#schema description#>
+  private func setSchema(_ schema: DataType) {
+    self.schema = schema
+  }
+
+  /// Add `Apache Arrow`'s `RecordBatch`s to the intenal array.

Review Comment:
   ```suggestion
     /// Add `Apache Arrow`'s `RecordBatch`s to the internal array.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #10:
URL: https://github.com/apache/spark-connect-swift/pull/10#discussion_r1990687505


##########
Sources/SparkConnect/DataFrame.swift:
##########
@@ -0,0 +1,195 @@
+//
+// 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 Atomics
+import Foundation
+import GRPCCore
+import GRPCNIOTransportHTTP2
+import GRPCProtobuf
+import NIOCore
+import SwiftyTextTable
+import Synchronization
+
+/// A DataFrame which supports only SQL queries
+public actor DataFrame: Sendable {
+  var spark: SparkSession
+  var plan: Plan
+  var schema: DataType? = nil
+  private var batches: [RecordBatch] = [RecordBatch]()
+
+  /// Create a new `DataFrame`instance with the given Spark session and plan.
+  /// - Parameters:
+  ///   - spark: A ``SparkSession`` instance to use.
+  ///   - plan: A plan to execute.
+  init(spark: SparkSession, plan: Plan) async throws {
+    self.spark = spark
+    self.plan = plan
+  }
+
+  /// Create a new `DataFrame` instance with the given SparkSession and a SQL statement.
+  /// - Parameters:
+  ///   - spark: A `SparkSession` instance to use.
+  ///   - sqlText: A SQL statement.
+  init(spark: SparkSession, sqlText: String) async throws {
+    self.spark = spark
+    self.plan = sqlText.toSparkConnectPlan
+  }
+
+  /// Set the schema. This is used to store the analized schema response from `Spark Connect` server.
+  /// - Parameter schema: <#schema description#>
+  private func setSchema(_ schema: DataType) {
+    self.schema = schema
+  }
+
+  /// Add `Apache Arrow`'s `RecordBatch`s to the intenal array.
+  /// - Parameter batches: A ``RecordBatch`` instance.

Review Comment:
   Oops. typo. Let me fix it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #10:
URL: https://github.com/apache/spark-connect-swift/pull/10#issuecomment-2716683724

   Thank you for helping this effort so far, @viirya . This is the last of initial implementation. After this, I'm moving forward to 
   - Adding more test cases for various data types and clarify the support matrix of types.
   - Adding missing features.
   - Polish the implementation .
   - Integrating with `Swift Package Index`.
   - Improving CIs by enabling the `Spark Connect` server via Docker in GitHub Action CIs.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #10:
URL: https://github.com/apache/spark-connect-swift/pull/10#discussion_r1990701420


##########
Tests/SparkConnectTests/SparkSessionTests.swift:
##########
@@ -0,0 +1,74 @@
+//
+// 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 `SparkSession`
+struct SparkSessionTests {
+  @Test
+  func sparkContext() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    await #expect(throws: SparkConnectError.UnsupportedOperationException) {
+      try await spark.sparkContext
+    }
+    await spark.stop()
+  }
+
+  @Test
+  func stop() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    await spark.stop()
+  }
+
+  @Test func userContext() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    let defaultUserContext = ProcessInfo.processInfo.userName.toUserContext
+    #expect(await spark.client.userContext == defaultUserContext)
+    await spark.stop()
+  }
+
+  @Test
+  func version() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(await spark.version.starts(with: "4.0.0"))
+    await spark.stop()
+  }
+
+  @Test
+  func conf() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(try await spark.conf.get("spark.app.name") == "Spark Connect server")
+    try await spark.conf.set("spark.x", "y")
+    #expect(try await spark.conf.get("spark.x") == "y")
+    #expect(try await spark.conf.getAll().count > 10)
+    await spark.stop()
+  }
+
+  @Test
+  func range() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(try await spark.range(10).count() == 10)

Review Comment:
   Oh, I mean in the current Github Actions, do we already have run Connect Server to run these tests?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun closed pull request #10: [SPARK-51483] Add `SparkSession` and `DataFrame` actors
URL: https://github.com/apache/spark-connect-swift/pull/10


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #10:
URL: https://github.com/apache/spark-connect-swift/pull/10#issuecomment-2716686412

   According to the review comment, I didn't mention `4.0.0 RC2` in `README.md` yet.
   - https://github.com/apache/spark-connect-swift/pull/4#discussion_r1988302867
   
   For now, this is supposed to support Apache Spark 4.0.0+ only.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #10:
URL: https://github.com/apache/spark-connect-swift/pull/10#discussion_r1990701937


##########
Tests/SparkConnectTests/SparkSessionTests.swift:
##########
@@ -0,0 +1,74 @@
+//
+// 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 `SparkSession`
+struct SparkSessionTests {
+  @Test
+  func sparkContext() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    await #expect(throws: SparkConnectError.UnsupportedOperationException) {
+      try await spark.sparkContext
+    }
+    await spark.stop()
+  }
+
+  @Test
+  func stop() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    await spark.stop()
+  }
+
+  @Test func userContext() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    let defaultUserContext = ProcessInfo.processInfo.userName.toUserContext
+    #expect(await spark.client.userContext == defaultUserContext)
+    await spark.stop()
+  }
+
+  @Test
+  func version() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(await spark.version.starts(with: "4.0.0"))
+    await spark.stop()
+  }
+
+  @Test
+  func conf() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(try await spark.conf.get("spark.app.name") == "Spark Connect server")
+    try await spark.conf.set("spark.x", "y")
+    #expect(try await spark.conf.get("spark.x") == "y")
+    #expect(try await spark.conf.getAll().count > 10)
+    await spark.stop()
+  }
+
+  @Test
+  func range() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(try await spark.range(10).count() == 10)

Review Comment:
   > Improving CIs by enabling the Spark Connect server via Docker in GitHub Action CIs.
   
   Ah, I see that it is in later steps. Thanks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #10:
URL: https://github.com/apache/spark-connect-swift/pull/10#discussion_r1990696675


##########
Tests/SparkConnectTests/SparkSessionTests.swift:
##########
@@ -0,0 +1,74 @@
+//
+// 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 `SparkSession`
+struct SparkSessionTests {
+  @Test
+  func sparkContext() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    await #expect(throws: SparkConnectError.UnsupportedOperationException) {
+      try await spark.sparkContext
+    }
+    await spark.stop()
+  }
+
+  @Test
+  func stop() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    await spark.stop()
+  }
+
+  @Test func userContext() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    let defaultUserContext = ProcessInfo.processInfo.userName.toUserContext
+    #expect(await spark.client.userContext == defaultUserContext)
+    await spark.stop()
+  }
+
+  @Test
+  func version() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(await spark.version.starts(with: "4.0.0"))
+    await spark.stop()
+  }
+
+  @Test
+  func conf() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(try await spark.conf.get("spark.app.name") == "Spark Connect server")
+    try await spark.conf.set("spark.x", "y")
+    #expect(try await spark.conf.get("spark.x") == "y")
+    #expect(try await spark.conf.getAll().count > 10)
+    await spark.stop()
+  }
+
+  @Test
+  func range() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(try await spark.range(10).count() == 10)

Review Comment:
   Yes, it works with the real server from now. Please see here.
   - https://swiftpackageindex.com/dongjoon-hyun/spark-connect-swift



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #10:
URL: https://github.com/apache/spark-connect-swift/pull/10#issuecomment-2716692413

   Thank you.
   
   For the record, the first MVP (Minimum Viable Product) is focusing on `SQL` area of Apache Spark 4.0.0 including the following.
   - SPARK-44444 Use ANSI SQL mode by default
   - SPARK-49555 SQL Pipe Syntax
   - SPARK-48338 Sql Scripting support for Spark SQL


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #10:
URL: https://github.com/apache/spark-connect-swift/pull/10#discussion_r1990677314


##########
Sources/SparkConnect/DataFrame.swift:
##########
@@ -0,0 +1,195 @@
+//
+// 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 Atomics
+import Foundation
+import GRPCCore
+import GRPCNIOTransportHTTP2
+import GRPCProtobuf
+import NIOCore
+import SwiftyTextTable
+import Synchronization
+
+/// A DataFrame which supports only SQL queries
+public actor DataFrame: Sendable {
+  var spark: SparkSession
+  var plan: Plan
+  var schema: DataType? = nil
+  private var batches: [RecordBatch] = [RecordBatch]()
+
+  /// Create a new `DataFrame`instance with the given Spark session and plan.
+  /// - Parameters:
+  ///   - spark: A ``SparkSession`` instance to use.
+  ///   - plan: A plan to execute.
+  init(spark: SparkSession, plan: Plan) async throws {
+    self.spark = spark
+    self.plan = plan
+  }
+
+  /// Create a new `DataFrame` instance with the given SparkSession and a SQL statement.
+  /// - Parameters:
+  ///   - spark: A `SparkSession` instance to use.
+  ///   - sqlText: A SQL statement.
+  init(spark: SparkSession, sqlText: String) async throws {
+    self.spark = spark
+    self.plan = sqlText.toSparkConnectPlan
+  }
+
+  /// Set the schema. This is used to store the analized schema response from `Spark Connect` server.
+  /// - Parameter schema: <#schema description#>
+  private func setSchema(_ schema: DataType) {
+    self.schema = schema
+  }
+
+  /// Add `Apache Arrow`'s `RecordBatch`s to the intenal array.
+  /// - Parameter batches: A ``RecordBatch`` instance.

Review Comment:
   Shouldn't it be an array?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #10:
URL: https://github.com/apache/spark-connect-swift/pull/10#discussion_r1990695806


##########
Tests/SparkConnectTests/SparkSessionTests.swift:
##########
@@ -0,0 +1,74 @@
+//
+// 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 `SparkSession`
+struct SparkSessionTests {
+  @Test
+  func sparkContext() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    await #expect(throws: SparkConnectError.UnsupportedOperationException) {
+      try await spark.sparkContext
+    }
+    await spark.stop()
+  }
+
+  @Test
+  func stop() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    await spark.stop()
+  }
+
+  @Test func userContext() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    let defaultUserContext = ProcessInfo.processInfo.userName.toUserContext
+    #expect(await spark.client.userContext == defaultUserContext)
+    await spark.stop()
+  }
+
+  @Test
+  func version() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(await spark.version.starts(with: "4.0.0"))
+    await spark.stop()
+  }
+
+  @Test
+  func conf() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(try await spark.conf.get("spark.app.name") == "Spark Connect server")
+    try await spark.conf.set("spark.x", "y")
+    #expect(try await spark.conf.get("spark.x") == "y")
+    #expect(try await spark.conf.getAll().count > 10)
+    await spark.stop()
+  }
+
+  @Test
+  func range() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(try await spark.range(10).count() == 10)

Review Comment:
   Hmm, so the test already connects to real server to execute a range plan?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51483] Add `SparkSession` and `DataFrame` actors [spark-connect-swift]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #10:
URL: https://github.com/apache/spark-connect-swift/pull/10#discussion_r1990695806


##########
Tests/SparkConnectTests/SparkSessionTests.swift:
##########
@@ -0,0 +1,74 @@
+//
+// 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 `SparkSession`
+struct SparkSessionTests {
+  @Test
+  func sparkContext() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    await #expect(throws: SparkConnectError.UnsupportedOperationException) {
+      try await spark.sparkContext
+    }
+    await spark.stop()
+  }
+
+  @Test
+  func stop() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    await spark.stop()
+  }
+
+  @Test func userContext() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    let defaultUserContext = ProcessInfo.processInfo.userName.toUserContext
+    #expect(await spark.client.userContext == defaultUserContext)
+    await spark.stop()
+  }
+
+  @Test
+  func version() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(await spark.version.starts(with: "4.0.0"))
+    await spark.stop()
+  }
+
+  @Test
+  func conf() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(try await spark.conf.get("spark.app.name") == "Spark Connect server")
+    try await spark.conf.set("spark.x", "y")
+    #expect(try await spark.conf.get("spark.x") == "y")
+    #expect(try await spark.conf.getAll().count > 10)
+    await spark.stop()
+  }
+
+  @Test
+  func range() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    #expect(try await spark.range(10).count() == 10)

Review Comment:
   Hmm, so the test already connects to real server?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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