rich7420 opened a new pull request, #7826:
URL: https://github.com/apache/datafusion-comet/pull/7826

   ## Which issue does this PR close?
   
   Part of #7818.
   
   ## Rationale for this change
   
   When Spark runs `explode` and the projection above it in one codegen stage, 
it finishes the current array before a root `LIMIT` stops it. In ANSI mode a 
later element of that array can raise. The cap from #6035 stops Comet's 
projection at the limit, so Comet returns a row instead:
   
   ```sql
   -- t has one Parquet row with a = array('1', '2', 'bad')
   SELECT CAST(x AS INT) FROM t LATERAL VIEW explode(a) e AS x LIMIT 1
   ```
   
   Spark raises `CAST_INVALID_INPUT`. Comet on main returns a row.
   
   ## What changes are included in this PR?
   
   - `Explode` gets an optional `fetch`. Once the native explode reaches it, it 
emits the rest of that input row's array and stops.
   - A projection over such an explode finishes each array before returning 
rows from it, even when the array spans batches. If a chunk fails, it retries 
shorter prefixes to find the first failing row and raises that row's error, so 
the error follows Spark's row order. If that row succeeds alone, it raises the 
original error.
   - In ANSI mode, `CometExecRule` sets the fetch instead of the cap for a root 
`CollectLimit` when Spark would fuse the projection with `explode` or 
`posexplode`, the generator reads from a scan or range, and the projection is 
deterministic with no UDFs or stateful expressions. Everything else is 
unchanged, including codegen off, where Spark projects only the rows it returns.
   - The compatibility guide lists the #7818 shapes still open: filters over 
generators, joins, and a `LIMIT` below an aggregate or sort in the same codegen 
stage.
   
   ## How are these changes tested?
   
   - `limit_explode.sql` (AQE on and off, batch size 2 and 8192): the same 
array, an array longer than 8192 elements, `posexplode`, map explode, 
`explode_outer` with empty and NULL arrays, the next array, `LIMIT` with 
`OFFSET`, errors in two different rows, and codegen off. On main the first 
query fails in all four configs. With the fetch alone, Comet misses the bad 
cast in the short array at batch size 2 and in the long array at 8192. Without 
the row-order check, Comet reports the bad cast instead of division by zero at 
8192.
   - Rust tests in `explode.rs` for the fetch, a split array, memory accounting 
for held chunks, and batch packing. The core and operators crate tests and 
Clippy pass.
   - `CometExecRuleSuite` checks that the fused plan uses the fetch, and that 
the cap stays with codegen off, with `NO_CODEGEN`, or with a projection that 
uses `CodegenFallback`, `rand` or a UDF.
   - On Spark 4.1, 1154 tests pass across `CometExecSuite`, 
`CometSqlFileTestSuite` and `CometExecRuleSuite`. The rule suite and the 
`limit_` fixtures pass on Spark 4.0 (168 tests) and 3.5 (164, one canceled by a 
version gate).
   - Not run: Spark's SQL tests, Spark 4.2, and timings.
   


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