Skip to content

[SPARK-52151] DataFrameWriterV2.overwrite should handle condition #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 8 additions & 2 deletions Sources/SparkConnect/DataFrameWriterV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public actor DataFrameWriterV2: Sendable {
/// output table.
/// - Parameter condition: A filter condition.
public func overwrite(condition: String) async throws {
try await executeWriteOperation(.overwrite)
try await executeWriteOperation(.overwrite, condition)
}

/// Overwrite all partition for which the ``DataFrame`` contains at least one row with the contents
Expand All @@ -120,7 +120,10 @@ public actor DataFrameWriterV2: Sendable {
try await executeWriteOperation(.overwritePartitions)
}

private func executeWriteOperation(_ mode: WriteOperationV2.Mode) async throws {
private func executeWriteOperation(
_ mode: WriteOperationV2.Mode,
_ overwriteCondition: String? = nil
) async throws {
var write = WriteOperationV2()

let plan = await self.df.getPlan() as! Plan
Expand All @@ -139,6 +142,9 @@ public actor DataFrameWriterV2: Sendable {
for property in self.tableProperties.toStringDictionary() {
write.tableProperties[property.key] = property.value
}
if let overwriteCondition {
write.overwriteCondition = overwriteCondition.toExpression
}
write.mode = mode

var command = Spark_Connect_Command()
Expand Down
Loading