Skip to content

[SPARK-51508] Support collect(): [[String?]] for DataFrame #17

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 2 commits into from

Conversation

dongjoon-hyun
Copy link
Member

@dongjoon-hyun dongjoon-hyun commented Mar 14, 2025

What changes were proposed in this pull request?

This PR aims to support DataFrame.collect() with the return type, an array of String array.

Why are the changes needed?

There are two main goals.

  1. Provide one of the simplest implementations for collect() API.
  2. Use it as a way to implement interim test coverage until we implement a more generic return type including complex types.

Does this PR introduce any user-facing change?

No, this is not released yet.

How was this patch tested?

Pass the CIs.

Was this patch authored or co-authored using generative AI tooling?

No.

@@ -58,7 +58,7 @@ public actor DataFrame: Sendable {

/// Add `Apache Arrow`'s `RecordBatch`s to the internal array.
/// - Parameter batches: An array of ``RecordBatch``.
private func addBathes(_ batches: [RecordBatch]) {
private func addBatches(_ batches: [RecordBatch]) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a typo fix.

return expression
}
sort.order = expressions
sort.isGlobal = true
Copy link
Member Author

@dongjoon-hyun dongjoon-hyun Mar 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I piggy-back this fix while improving a test coverage by checking the result via collect() API.

#if os(iOS) || os(watchOS) || os(tvOS)
let userName = processInfo.environment["SPARK_USER"] ?? ""
#elseif os(macOS) || os(Linux)
#if os(macOS) || os(Linux)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified the implementation in a new way to cover os(visionOS) too.

@@ -125,19 +125,25 @@ struct DataFrameTests {
await spark.stop()
}

#if !os(Linux)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Like show(), collect() currently has a binary compatibility issue on os(Linux).
  • On MacOS, all tests pass.

@dongjoon-hyun
Copy link
Member Author

Could you review this, @viirya ? I added the first implementation for collect() API for users and for easy testing method.

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-51508] Support collect(): [[String]] for DataFrame [SPARK-51508] Support collect(): [[String?]] for DataFrame Mar 14, 2025
Comment on lines +172 to +173
for column in batch.columns {
let str = column.array as! AsString
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For DataFrame, I suppose that the return of collect is an array of Row. But this collect returns strings. Is it just for initial implementation and will be Row later?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, correct. Row implementation is on the way~

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Scala client, we also support Array[Long] like the following.

$ bin/spark-shell --remote sc://localhost:15002
scala> spark.range(1).collect()
res0: Array[java.lang.Long] = Array(0L)

@dongjoon-hyun
Copy link
Member Author

Thank you for helping this moving forward, @viirya !
Merged to main.

@dongjoon-hyun dongjoon-hyun deleted the SPARK-51508 branch March 14, 2025 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants