dongjoon-hyun opened a new pull request, #620: URL: https://github.com/apache/spark-connect-swift/pull/620
### What changes were proposed in this pull request? This PR aims to fix the single-column `DataFrameStatFunctions.approxQuantile(_:_:_:)` to throw `SparkConnectError.invalidState` instead of crashing when the server returns an empty list of quantiles. It uses the existing `Array.firstOrThrow()` helper instead of `[0]`. ### Why are the changes needed? The single-column version returns the first element of the multi-column result with `[0]`, which has no bounds check. So, an empty result crashes the client process. ``` Swift/ContiguousArrayBuffer.swift:695: Fatal error: Index out of range ``` A Spark Connect server returns one list of quantiles per requested column ([SparkConnectPlanner.transformStatApproxQuantile](https://github.com/apache/spark/blob/v4.2.0/sql/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala#L576-L587) in [v4.2.0](https://github.com/apache/spark/releases/tag/v4.2.0) (2026-07-11)), so this happens only with a misbehaving or incompatible server. As described in SPARK-59193, such a server should cause a catchable error instead of crashing the client application. SPARK-59193 and SPARK-60352 fixed the other traps in this file, but this `[0]` remained. In the same case, the Scala client ([DataFrameStatFunctions.approxQuantile](https://github.com/apache/spark/blob/v4.2.0/sql/api/src/main/scala/org/apache/spark/sql/DataFrameStatFunctions.scala#L74-L79)) and the Python client ([DataFrame.approxQuantile](https://github.com/apache/spark/blob/v4.2.0/python/pyspark/sql/connect/dataframe.py#L1751-L1753)) raise catchable exceptions, `NoSuchElementException` and `IndexError`. ### Does this PR introduce _any_ user-facing change? No for normal usage. When the server returns an empty list of quantiles, the single-column `approxQuantile` now throws `SparkConnectError.invalidState` instead of crashing. ``` The server returned an empty response for approxQuantile(_:_:_:). ``` ### How was this patch tested? Pass the CIs. No test case is added because a Spark Connect server returns an empty list of quantiles only for an empty list of columns, so the changed code path cannot be tested without a mock server. `firstOrThrow()` on an empty array is covered by `ExtensionTests.firstOrThrowOnEmptyArray`, and the existing `DataFrameStatFunctionsTests.approxQuantile` covers the normal and empty `DataFrame` cases. In addition, this was verified manually against an `apache/spark:4.2.0` Spark Connect server with a temporary client interceptor which removes the column from the `StatApproxQuantile` request. The single-column `approxQuantile` crashed with `Fatal error: Index out of range` before this fix, and throws `SparkConnectError.invalidState` after this fix. `DataFrameStatFunctionsTests` and `ExtensionTests` also passed against `apache/spark:4.2.0` and `apache/spark:4.0.4-java21-scala` Spark Connect servers. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Opus 5.5 -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
