anuragmantri opened a new issue, #71:
URL: https://github.com/apache/datafusion-iceberg/issues/71

   With `iceberg.planning.preserve_data_ordering`, #55 merges one reader per 
data file with every file open at once, so `iceberg.planning.max_merge_files` 
caps the number of files. A sorted table with many small commits goes over the 
cap and loses its order, even when most of its files don't overlap.
   
   The plan is to bound the merge by overlap instead of file count. 
`IcebergDataSource` would read each file's bounds and null counts for the sort 
columns, sort the files by their first key in output order, and put each file 
after the first chain whose last file ends at or before it. DataFusion's 
`split_groups_by_statistics` does the same. Each chain is read one file at a 
time, the chains are k-way merged, and `max_merge_files` applies to the number 
of chains, which equals the maximum overlap depth. A table whose files don't 
overlap then merges nothing.
   
   Cases that need care:
   - Files are compared over every claimed sort key, not just the leading one. 
With a tie on the leading key, comparing only that key could put one file's 
rows ahead of the other's when the second key says otherwise.
   - Under NULLS FIRST a file with nulls can only start a chain, and under 
NULLS LAST it can only end one. A missing null count on an optional column 
counts as nulls.
   - Descending keys swap the bounds.
   - Truncated string bounds stay correct; they just overlap more.
   - A file with missing bounds, or a bound typed differently from the column 
after a type promotion, gets a chain of its own. With no bounds at all, the 
scan behaves exactly as after #55.
   - Listing every file at planning time also needs a cap of its own.
   
   This needs per-file column statistics on `FileScanTask`, which iceberg-rust 
doesn't carry today. I'm preparing that iceberg-rust change and will link it 
here. It will then need a bump of the iceberg-rust `rev`.
   
   Related: In 
https://github.com/apache/datafusion-comet/pull/5331#discussion_r3830848772, 
@mbutrovich proposed admitting unopened files from a priority queue ordered by 
min bound. That bounds open readers by the same overlap depth and opens files 
later, which helps `LIMIT`, but it needs a custom merge operator. Chains reuse 
`StreamingMergeBuilder`, so I'd start there and keep admission as a possible 
next step.
   
   I'm working on this and will put up the PR here once #55 and the 
iceberg-rust change have merged.


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