- Notifications
You must be signed in to change notification settings - Fork 343
feat(core): Add support for _file column #1824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| /// // Select regular columns along with the file path | ||
| /// let scan = table | ||
| /// .scan() | ||
| /// .select(["id", "name", RESERVED_COL_NAME_FILE]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we ask for _file column without having to explicitly list all the other columns? E.g. get me all columns + _file. There should be some shortcut for this.
_file column_file column …erg-rust into feature/gb/file-column
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gbrgr for this pr. But I think we need to rethink how to compute the _file, _pos metadata column. While it's somehow trivial to compute _file, it's non trivial to compute _pos efficient, since when we read parquet files, we have filtered out some row groups. I think the best way is to push reading these two columns to arrow-rs.
| pub(crate) const RESERVED_FIELD_ID_FILE: i32 = 2147483646; | ||
| | ||
| /// Column name for the file path metadata column per Iceberg spec | ||
| pub(crate) const RESERVED_COL_NAME_FILE: &str = "_file"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add a metadata_columns module similar to what java did: https://github.com/apache/iceberg/blob/bb32b90c4ad63f037f0bda197cc53fb08c886934/core/src/main/java/org/apache/iceberg/MetadataColumns.java#L2
@liurenjie1024 I agree for How do we go forward with rethinking this, what would be the action items for us? |
Which issue does this PR close?
_filemetadata column #1766.What changes are included in this PR?
This PR adds support for the
_filereserved column in Iceberg table scans, allowing users to retrieve the file path for each row in their query results. This is useful for debugging, auditing, and tracking data lineage.Core Implementation
Reserved column constants (reader.rs):
RESERVED_FIELD_ID_FILE = 2147483646- reserved field ID per Iceberg specRESERVED_COL_NAME_FILE = "_file"- column name per Iceberg specPublic API (scan/mod.rs):
RESERVED_COL_NAME_FILEas a public constant in theiceberg::scanmoduleKey Features
["col1", "_file", "col2"], the_filecolumn appears in the correct position (second)Usage Example
Are these changes tested?
Yes, comprehensive tests have been added to verify the functionality:
New Tests (9 tests added)
Table Scan API Tests (7 tests)
test_select_with_file_column- Verifies basic functionality of selecting_filewith regular columnstest_select_file_column_position- Verifies column ordering is preservedtest_select_file_column_only- Tests selecting only the_filecolumntest_file_column_with_multiple_files- Tests multiple data files scenariotest_file_column_at_start- Tests_fileat position 0test_file_column_at_end- Tests_fileat the last positiontest_select_with_repeated_column_names- Tests repeated column selectionArrow Reader Helper Tests (2 tests)
test_add_file_path_column_ree- Tests theadd_file_path_column_ree_at_position()helpertest_add_file_path_column_ree_empty_batch- Tests empty batch handling