comphead commented on PR #7636: URL: https://github.com/apache/datafusion-comet/pull/7636#issuecomment-7291240206
Thanks @andygrove, dictionaries are a second exception, and a slice of one can grow the block. **Can a dictionary column reach the writer?** I could not find a path from a Comet plan. `ScanExec` builds its schema without dictionary types and casts each input column to it, the native Parquet scan casts dictionary-encoded columns to the Spark type, and `ShuffleScanExec` unpacks what it reads. Dictionary-encoded shuffle blocks come from the JVM columnar shuffle (`process_sorted_row_partition` with `prefer_dictionary_ratio`), which writes its blocks without this partitioner. The partitioner still accepts them, as the `multi_partition.rs` tests show, so I treated them as reachable. **Does a slice grow the block?** arrow-ipc 59.3.2 writes the whole values array of a sliced dictionary, as you read. But `interleave` drops the unreferenced values only when the source dictionaries differ and hold at least as many values as the output has rows. When the buffered batches share one dictionary, it concatenates one copy per buffered batch (https://github.com/apache/arrow-rs/issues/12056). Small distinct dictionaries are concatenated whole (https://github.com/apache/arrow-rs/issues/9939). So it goes both ways. Block bytes for one partition's rows out of eight buffered 8192-row batches, with an `Int64` and a `Dictionary(Int32, Utf8)` column of 40-byte strings and random keys, gather / slice before this fix, in KiB: | dictionaries | rows taken | uncompressed | lz4 | zstd(1) | | --- | --- | --- | --- | --- | | one shared, 4096 values | every row (8 blocks) | 11782 / 2150 | 2820 / 779 | 1073 / 355 | | per batch, 4096 values | every row (8 blocks) | 1988 / 2182 | 733 / 779 | 346 / 340 | | per batch, 4096 values | one 2000-row run | 92 / 200 | 29 / 52 | 16 / 23 | | per batch, 64 values | 256-row runs (2 blocks) | 237 / 369 | 106 / 123 | 46 / 60 | Since a slice can grow the block, b5d59f6055 takes your first option: rows of a schema with a dictionary anywhere are gathered, as rows of a schema with a view type are. With it, all 12 shapes I measured (three dictionary layouts by four row selections, including a scattered one) write the same blocks as the gather under every codec. - `always_gathered` in `partitioned_batch_iterator.rs` decides for both, with `contains_view_type` for view types and `flattened_fields` for dictionaries at any depth. It runs once per flush, as the view check did. - `view_columns_are_gathered_even_when_contiguous` became `view_and_dictionary_columns_are_gathered_even_when_contiguous` and also covers a `Dictionary(Int32, Utf8)` column and a struct holding one. It fails if the dictionary check is removed, or if it looks only at top-level fields. - The shuffle guide and the `contains_view_type` and `concat_slices` comments now name dictionaries as the second type whose slices the writer does not truncate. Positional placement (`RowGroups`, off by default) still slices dictionary columns, as it did before this PR. I left it alone because this PR does not touch it, and falling back to `HashAll` would send shared dictionaries through the concatenating gather above. The numbers come from a scratch test that is not in the PR. The sizes are deterministic, so they do not depend on the machine. -- 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]
