KarpagamKarthikeyan opened a new pull request, #23962: URL: https://github.com/apache/datafusion/pull/23962
## Which issue does this PR close? - Closes #23961 - Part of #15914 ## Rationale for this change Spark provides [`atan2(exprY, exprX)`](https://spark.apache.org/docs/latest/api/sql/#atan2), which returns the angle in radians between the positive x-axis and the point given by the coordinates (`exprX`, `exprY`). It was not yet implemented in `datafusion-spark` — only an auto-generated test stub existed at `spark/math/atan2.slt` with its query commented out. ## What changes are included in this PR? - Add `SparkAtan2` (implementing `ScalarUDFImpl`) in `datafusion/spark/src/function/math/atan2.rs`, computing `y.atan2(x)` element-wise via the Arrow `binary` kernel. - Register it in `datafusion/spark/src/function/math/mod.rs`. - Enable the `atan2.slt` sqllogictest. The signature is `exact(Float64, Float64) -> Float64`, following the `datafusion-spark` convention of only accepting Spark-supported types. NULL in either argument propagates to NULL. Note: DataFusion core already has an `atan2`, but this is implemented self-contained rather than delegating — matching the crate convention, where 14 of the 15 existing `math` functions reimplement rather than wrap core (including `abs`, `ceil`, `floor`, `round`, `rint`, all of which also exist in core; only `pow` delegates, as a special case). This keeps the Spark function library complete and consistent. ## Are these changes tested? Yes — `datafusion/sqllogictest/test_files/spark/math/atan2.slt` covers: - standard angles and all four quadrants (atan2 is quadrant-aware via the signs of both arguments), - both axes and the negative x-axis (atan2's range extends to π, unlike `atan`), - NULL propagation (either argument) and NULL-beats-Infinity, - NaN in every position, including `atan2(NaN, Infinity) = NaN` (for atan2, NaN propagates even over Infinity — unlike `hypot`, where Infinity dominates), - all four infinity quadrants and the one-infinite-argument cases, - signed zeros (`atan2(-0, -1) = -π`), - the array path (including a NULL row). ## Are there any user-facing changes? Yes — adds the Spark-compatible `atan2` scalar function to `datafusion-spark`. No breaking changes to public APIs. -- 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]
