-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Is your feature request related to a problem or challenge? Please describe what you are trying to do.
Deletion vectors in the Delta Lake and Iceberg table formats are defined in terms of row numbers within individual Parquet files. To be able to filter out rows defined as deleted by deletion vectors we need a way to know the file row number of the rows read by the Arrow Parquet reader.
Describe the solution you'd like
The Arrow Parquet reader should optionally return a column containing the row number of each row. We add a method ArrowReaderBuilder::with_row_numbers(self, with_row_numbers: bool) -> Self, which configures the Arrow Parquet reader to add an extra column named row_number to its schema (possibly the method could be ArrowReaderBuilder::with_row_number_column(self, with_row_numbers: Option<String>) -> Self to make the column name configurable). This column contains the row number within the file.
Describe alternatives you've considered
There is a corresponding issue on Datafusion apache/datafusion#13261. It considers an alternative using primary keys and existing SQL primitives, but this comes with a performance penalty. The consensus on the issue is
I agree with the assessment that the information must be coning from the file reader itself.
The idea is to produce a new column, so if a file had a column A with this feature the parquet reader would add a new row_number column, like
| A | row_number |
|---|---|
| x | 0 (row number increases sequentially) |
| y | 1 |
| d | 2 |
| q | 3 |
| a | 4 |
| .. | .. |
| q | 100 |
This would also account for predicates, so for example if we selected only rows with A = 'q' above the output would be
| A | row_number |
|---|---|
| q | 3 |
| q | 100 |
That is, the Arrow Parquet reader.
Additional context
Please see apache/datafusion#13261 for the corresponding issue in Datafusion. There is also a discussion in Datafusion to add system/metadata columns in apache/datafusion#14057 through which this additional file row number column could be exposed. Though, we do not need system/metadata columns to be available to support deletion vectors in delta-rs or iceberg-rs, since the delta-rs and iceberg-rs Datafusion based readers use the Datafusion ParquetSource directly to construct the execution plans for the scans of their TableProviders.
Activity
alamb commentedon Mar 18, 2025
I think adding this to the reader seems reasonable to me if there is a way to:
jkylling commentedon Mar 18, 2025
I've started on this in #7307. Please let me know if you think the approach is reasonable.
alamb commentedon Sep 25, 2025
There is lots of good discussion. Here is one from @scovich: #7307 (comment) about how other readers represent row numbers
#7307 (comment), posted Apr 15, might be a starting point?
Duckdb uses a column schema type approach. Interestingly, that's new -- last time I looked (nearly a year go) it required the reader to pass options along with the schema, and one of the options was to request row numbers (which then became an extra unnamed column at the end of the regular schema). I think that approach didn't scale as they started needing more and more special column types. I see geometry, variant, and non-materialiaed expressions, for example.
Iceberg's parquet reader works almost exclusively from field ids, and row index has a baked in field id from the range of metadata row ids.
Spark uses a metadata column approach, identified by a special name (
_metadata._rowid); I don't remember how precisely that maps to the underlying parquet reader.[-]Return file row number in Parquet readers[/-][+]Support file row number in Parquet reader[/+]alamb commentedon Oct 17, 2025
i filed another ticket for something very similar (row group index)
alamb commentedon Oct 17, 2025
I also added an example to this ticket in the description
_posmetadata column iceberg-rust#1765alamb commentedon Oct 21, 2025
Copying a comment I made in discord:
I recommend sketching out an "end to end" example that shows how the new API would work
For example, make an example similar to this one that shows how you would specify reading row numbers and how you would access those row numbers in the returned batch
https://docs.rs/parquet/latest/parquet/arrow/index.html#example-reading-parquet-file-into-arrow-recordbatch
vustef commentedon Oct 22, 2025
Here's an example:
Rough ideas behind this:
falsefor nullability andArrowDataType::Int64.builder.with_row_number_column(field). The alternative is to make users create full schema and insert this field somewhere in it, but that doesn't seem user-friendly always. Rather,with_row_number_columnwould add this field to the end of thefieldslist in the schema.with_row_number_columnshould also modifyArrowReaderBuilder::fields, to add a new field. I'm not sure whatfield_typeit should have there. Probably needs a new one, so that the array reader builders would build a special array reader, that enumerates row positions, and information about extension type would otherwise be lost at this point.Please let me know what you think.
jkylling commentedon Oct 23, 2025
This looks really good!
How about:
This can be used with (1) (I believe this pattern is common in engines, even if not user friendly):
and (2)
Alternatively, we modify (2) to be:
(3)
as this might simplify the changes to
ParquetRecordBatchReaderBuilder(it might be unchanged?).This would allow us to do #8641 in the future without having to change the interface of
ArrowReaderOptionsorParquetRecordBatchReaderBuilderfurther.16 remaining items