mbutrovich commented on code in PR #4816: URL: https://github.com/apache/datafusion-comet/pull/4816#discussion_r4066323016
########## docs/source/contributor-guide/expression-audits/agg_funcs.md: ########## @@ -70,6 +70,14 @@ - Comet implementation: the native side delegates to `datafusion_spark::function::aggregate::collect::SparkCollectSet`, which wraps `DistinctArrayAggAccumulator` with `ignore_nulls = true` in a `NullToEmptyListAccumulator` so a final NULL accumulator state becomes an empty array. The `containsNull` mismatch against Spark's declared output type, and its rationale, are identical to [collect_list](#collect-list). - `CometCollectSet` reports `Incompatible` for float and double input when `spark.comet.exec.strictFloatingPoint=true`, because the native distinct comparison treats `NaN == NaN` and collapses repeated `NaN`s into a single element while Spark keeps each one. The native path for floating-point input is then opt-in via `spark.comet.expression.CollectSet.allowIncompatible=true`. All other input types are `Compatible`. +## listagg + +- Spark 3.4.3 (audited 2026-07-03): does not exist. `ListAgg` was added in Spark 4.0. +- Spark 3.5.8 (audited 2026-07-03): does not exist. +- Spark 4.0.1 (audited 2026-07-03): `ListAgg(child, delimiter, orderExpressions)` in `aggregate/collect.scala`. Accepts `StringType` or `BinaryType` inputs; result type matches child. Skips nulls; empty or all-null groups return `NULL`. A `NULL` delimiter is treated as an empty string. `CometListAgg` maps only the simple form: `StringType` child with a literal `StringType`/`NullType` delimiter and no `WITHIN GROUP`. `BinaryType` inputs, `WITHIN GROUP (ORDER BY ...)`, non-literal delimiters, and non-default collations fall back to Spark. `DISTINCT` falls back because Comet rejects multi-column distinct aggregates (`ListAgg` has two children). +- Spark 4.1.1 (audited 2026-07-03): byte-identical to 4.0.1. +- Native accumulator (`SparkListAgg`) returns `Utf8` and carries its intermediate state as `Utf8`. Partial and final always run in the same engine (`supportsMixedPartialFinal` is false), so no cross-engine buffer-schema matching is required. A `GroupsAccumulator` fast path is provided for grouped aggregation. Review Comment: This still says the state is `Utf8` and that no buffer-schema matching is needed. That's the reverse of what the code does now: the state is `Binary` to match Spark's `TypedImperativeAggregate` buffer at the Exchange ([`list_agg.rs` lines 94-108](https://github.com/apache/datafusion-comet/blob/f2d1c1b02605020d69df21220bdb6272a43f6bba/native/spark-expr/src/agg_funcs/list_agg.rs#L94-L108)). Since the audit docs are what the next person reads before touching this, could you update it to match the `state_fields` comment? ```suggestion - Native accumulator (`SparkListAgg`) returns `Utf8` and carries its intermediate state as `Binary`. Spark's `ListAgg` is a `TypedImperativeAggregate` with a single `BinaryType` buffer attribute, and the shuffle Exchange between the partial and final aggregate uses that schema, so the native state must be `Binary` even though partial and final always run in Comet (`supportsMixedPartialFinal` is false). A `GroupsAccumulator` fast path is provided for grouped aggregation. ``` ########## spark/src/main/spark-4.x/org/apache/comet/serde/CometListAgg.scala: ########## @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.comet.serde + +import org.apache.spark.sql.catalyst.expressions.Attribute +import org.apache.spark.sql.catalyst.expressions.aggregate.{AggregateExpression, ListAgg} +import org.apache.spark.sql.internal.SQLConf +import org.apache.spark.sql.types.{NullType, StringType} + +import org.apache.comet.CometSparkSessionExtensions.withFallbackReason +import org.apache.comet.serde.QueryPlanSerde.{exprToProto, hasNonDefaultStringCollation} + +/** + * Spark 4.0+ `LISTAGG` / `STRING_AGG`. + * + * Comet only supports the simple form: a `StringType` child with a literal delimiter and no + * `WITHIN GROUP (ORDER BY ...)` clause. DISTINCT is handled by Spark's multi-stage plan rewrite + * (grouping by the child before the aggregate), so the native side never sees it. Review Comment: This says DISTINCT is handled by Spark's multi-stage rewrite, but the comment at lines 44-46 and the test at `listagg.sql` line 110 show it falls back through Comet's multi-column distinct check in `aggExprToProto`. The same claim is in the `list_agg.rs` module doc ([lines 20-22](https://github.com/apache/datafusion-comet/blob/f2d1c1b02605020d69df21220bdb6272a43f6bba/native/spark-expr/src/agg_funcs/list_agg.rs#L20-L22)) and the `ListAgg` message comment in `expr.proto` (line 359). Could you align all three with what actually happens? ```suggestion * Comet only supports the simple form: a `StringType` child with a literal delimiter and no * `WITHIN GROUP (ORDER BY ...)` clause. DISTINCT falls back to Spark because Comet rejects * multi-column distinct aggregates in `aggExprToProto`, so the native side never sees it. ``` -- 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]
