andygrove commented on issue #7267: URL: https://github.com/apache/datafusion-comet/issues/7267#issuecomment-7396126763
With 20 sub-issues open and several fixes in flight, we're starting to solve the same problem in different ways. #7787 cuts batches at a 1 GiB UnsafeRow budget, #7316 adds a split operator, #7762 lowers the batch size for a subtree, #7746 checks output sizes before writing, and the plan on #7269 adds a retry on overflow. Each is reasonable for its own site, but we'll end up with five mechanisms and five kinds of test. I'd like us to agree on one approach before more of these land. Going through the sub-issues, the sites fall into five kinds, and each kind needs a different fix: - Sources that cut batches by row count only: #7276, #7277, #7496, #7497, #7498, #7499, #7502. - Mergers that combine batches that are each fine into one that isn't: #7269, #7271, #7272, #7278, #7279, #7501. - Expanders, whose output is bigger than their input: #7500, #7495, #7247. - Operators that concatenate their whole input whatever the batch size: #7270, #7273, #7274. - Sites that panic or abort on overflow instead of returning an error: #7503, #7803, and parts of #7500 and #7501. The first thing I'd like is a floor that applies everywhere: an offset overflow is always a `CometNativeException` that names the setting to lower, never a panic or an abort. It's cheap, it doesn't depend on anything else, and a panic that escapes JNI is undefined behavior. For sources and mergers, I think we want a single byte budget defined in one place, which every batch leaving a source or a merger respects for each variable-width column. #7787 already picked 1 GiB, which leaves room for an operator that doubles a column, like `concat(a, a)`. Could we make it an internal config so that tests can set it to a few MB? The budget can't be a guarantee, because projections and joins downstream can widen a column again, so mergers also need to retry with fewer rows on `OffsetOverflowError`. DataFusion's sort merge already does this (`retry_interleave` in `sorts/builder.rs`). I'd like the helpers to live in one module in `native/common`, so that each fix calls them instead of carrying its own copy: - byte counts for a row range, read from the offsets (including nested types) - zero-copy splitting of a batch to the budget (the split operator from #7316, cutting by bytes as well as rows) - a byte-bounded wrapper around arrow's `BatchCoalescer` - concat and interleave that retry on overflow - checked appends for our own builders, like the ones in #7809 - a way for tests to lower the offset limit itself, so we can test the retry and error paths without 2 GiB of data Expanders check the output size before allocating. Then they either return the error or split, depending on whether the input can be split. Lowering the batch size will never fix the operators that concatenate their whole input. Rather than wait for DataFusion to stop concatenating join build sides (apache/datafusion#23031), I'd like to try view types locally. In arrow 59.3.1, casting `Utf8` to `Utf8View` reuses the data buffer and only allocates 16 bytes per row, and `concat` and `interleave` on views add the input buffers to the output without copying them, so the 2 GiB total goes away. The planner would cast string and binary columns to views below `WindowAggExec`, a join's build side, `BoundedWindowAggExec` and TopK. Above the operator, it would split the output to the budget before casting back to `Utf8`. It has to split first, because 8192 rows of 1 MB each would overflow again on the way back. I'd prove this on `WindowAggExec` (#7270) with a benchmark before applying it anywhere else. It might also be simpler than the `LargeUtf8` promotion in #4791 for group keys. Using view types throughout Comet (#7275) is a much bigger change, and I'd keep it outside this epic. For testing, I'd suggest one SQL test suite over a wide-value column, run with a tiny budget and a lowered offset limit. It would cover every operator listed here and compare the results with Spark. That's in place of each PR building its own fixture. As for order: the shared helpers first, mostly extracted from #7787 and #7316, and then the panic-to-error sweep. After that, the source and merger fixes can move onto the helpers. Anyone who has already claimed one of those sub-issues can carry on and just call the shared code. The view-type experiment can run in parallel, and the byte limit in arrow's `BatchCoalescer` (#7271) can go upstream whenever someone picks it up. One open question is scalar expansion (#7247). #7316 and #7762 handle it by limiting rows per batch, and #7762 adds a scope operator that lowers the batch size for a subtree. Could the byte-based split cover the same cases, so that we only have one mechanism? I'd like to settle that before #7762 leaves draft. Thoughts? -- 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]
