xanderbailey opened a new pull request, #437:
URL: https://github.com/apache/datafusion-spark/pull/437

   ## Which issue does this PR close?
   
   - No issue yet. Happy to open one if you'd like to discuss scope first, 
since `product` is internal in Spark (see below).
   
   ## Rationale for this change
   
   Spark's `product` aggregate (`Product`) has no DataFusion equivalent: 
DataFusion has no `product`, and neither does Comet's `spark-expr`. Engines 
that run Spark plans on DataFusion therefore can't execute `F.product`.
   
   Spark registers it with `registerInternalExpression`, so it's reachable from 
the DataFrame API (`pyspark.sql.functions.product`, Scala's 
`functions.product`) but not from Spark SQL, where `SELECT product(x)` fails 
with `UNRESOLVED_ROUTINE`.
   
   ## What changes are included in this PR?
   
   - `product` in `crates/spark/src/function/aggregate/product.rs`. It declares 
Spark's `inputTypes = Seq(DoubleType)` through `SparkInputTypes`, returns 
DOUBLE, skips NULLs and is NULL when there are no non-NULL values, matching 
Spark's `coalesce(product, 1.0) * child`.
     - A `GroupsAccumulator` built on `PrimitiveGroupsAccumulator`.
     - A sliding accumulator for bounded window frames. It keeps the frame's 
values and recomputes the product, because dividing a removed value back out 
can't undo an overflow to Infinity or a zero, and drifts. This is also how 
Spark evaluates a sliding frame.
   - The PySpark runner registers Spark's own builder for internal functions 
(`INTERNAL_FUNCTIONS`, currently just `product`) as session temporary 
functions, so SQL resolves `product` to the same `Product` expression the 
DataFrame API builds and the `.slt` records run on Spark too.
   - `docs/functions` regenerated.
   
   ## Are these changes tested?
   
   - `aggregate/product.slt` covers nulls and empty input, every numeric input 
type, BIGINT products past the long range, overflow and underflow to signed 
Infinity and zero, NaN and Infinity × 0, strings, booleans, `GROUP BY`, a 
running window and bounded sliding frames, in both ANSI modes where they differ.
   - Unit tests in `product.rs` cover the accumulators directly, including 
retracting from a sliding frame past an overflow.
   - Checked against Spark 4.2.0 with the PySpark runner: 33 records pass and 1 
is an expected failure. With ANSI off, Spark's legacy cast turns a malformed 
string into NULL, while the implicit cast here is DataFusion's strict one; 
marked `xfail spark` against #88.
   - I also compared the same cases through `F.product` on PySpark 3.5.10 and 
4.2.0 and got identical results.
   
   ## Are there any user-facing changes?
   
   A new `product` aggregate function.
   


-- 
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]

Reply via email to