Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Sources/SparkConnect/DataFrameReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ public actor DataFrameReader: Sendable {
return load(paths)
}

/// Loads an XML file and returns the result as a `DataFrame`.
/// - Parameter path: A path string
/// - Returns: A `DataFrame`.
public func xml(_ path: String) -> DataFrame {
self.source = "xml"
return load(path)
}

/// Loads XML files and returns the result as a `DataFrame`.
/// - Parameter paths: Path strings
/// - Returns: A `DataFrame`.
public func xml(_ paths: String...) -> DataFrame {
self.source = "xml"
return load(paths)
}

/// Loads an ORC file and returns the result as a `DataFrame`.
/// - Parameter path: A path string
/// - Returns: A `DataFrame`.
Expand Down
8 changes: 8 additions & 0 deletions Sources/SparkConnect/DataFrameWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ public actor DataFrameWriter: Sendable {
return try await save(path)
}

/// Saves the content of the `DataFrame` in XML format at the specified path.
/// - Parameter path: A path string
/// - Returns: A `DataFrame`.
public func xml(_ path: String) async throws {
self.source = "xml"
return try await save(path)
}

/// Saves the content of the `DataFrame` in ORC format at the specified path.
/// - Parameter path: A path string
/// - Returns: A `DataFrame`.
Expand Down
10 changes: 10 additions & 0 deletions Tests/SparkConnectTests/DataFrameReaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ struct DataFrameReaderTests {
await spark.stop()
}

@Test
func xml() async throws {
let spark = try await SparkSession.builder.getOrCreate()
let path = "../examples/src/main/resources/people.xml"
#expect(try await spark.read.option("rowTag", "person").format("xml").load(path).count() == 3)
#expect(try await spark.read.option("rowTag", "person").xml(path).count() == 3)
#expect(try await spark.read.option("rowTag", "person").xml(path, path).count() == 6)
await spark.stop()
}

@Test
func orc() async throws {
let spark = try await SparkSession.builder.getOrCreate()
Expand Down
9 changes: 9 additions & 0 deletions Tests/SparkConnectTests/DataFrameWriterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ struct DataFrameWriterTests {
await spark.stop()
}

@Test
func xml() async throws {
let tmpDir = "/tmp/" + UUID().uuidString
let spark = try await SparkSession.builder.getOrCreate()
try await spark.range(2025).write.option("rowTag", "person").xml(tmpDir)
#expect(try await spark.read.option("rowTag", "person").xml(tmpDir).count() == 2025)
await spark.stop()
}

@Test
func orc() async throws {
let tmpDir = "/tmp/" + UUID().uuidString
Expand Down
Loading