gaborkaszab commented on code in PR #16425: URL: https://github.com/apache/iceberg/pull/16425#discussion_r4708616704
########## format/spec.md: ########## @@ -1748,7 +1752,9 @@ The rows in the delete file must be sorted by `file_path` then `pos` to optimize Equality delete files identify deleted rows in a collection of data files by one or more column values, and may optionally contain additional columns of the deleted row. -Equality delete files must not be added to v4 tables. Equality deletes cannot be added as an entry to a v4 manifest. Equality delete files referenced by v2 or v3 delete manifests must still be applied in a v4 table. +Equality delete files must not be added to v4 tables and cannot be written to new v4 leaf manifests. Equality delete files tracked by existing v2 or v3 delete manifests must still be applied in a v4 table. + +When a data file is updated by adding a column file, its data sequence number is updated so that updated rows inherit a new `_last_updated_sequence_number`. Because the data sequence number changes, the equality deletes that apply to the file must be rewritten into its deletion vector. Review Comment: "so that updated rows inherit a new `_last_updated_sequence_number`" I'm not sure that part is needed. A simpler explanation could be: "When a data file is updated by adding a column file, it gets a new data sequence number. As a result, equality deletes that applied to the data file no longer apply, and they must be rewritten into a deletion vector." ########## format/spec.md: ########## @@ -1203,13 +1206,13 @@ Values for `snapshot_id`, `sequence_number`, and `file_sequence_number` are inhe Manifests track the sequence number when a data or delete file was added to the table. -The `sequence_number` field represents the data sequence number. It is set when a file is added to the dataset and must not change unless a column file is added. The data sequence number represents a relative age of the file content and should be used for planning which delete files apply to a data file. +The `sequence_number` field represents the data sequence number. It is set when a file is added to the dataset or when a column file modifies its rows, and must not change otherwise. The data sequence number is inherited to the row level as `_last_updated_sequence_number`. A data file's sequence number is also used to determine which equality delete files apply to a data file. Review Comment: "A data file's sequence number is also used to determine which equality delete files apply to a data file." The delete file section says that data sequence number is used for dv's in a delete manifest, and position deletes too. Aren't we narrowing this too much here? ########## format/spec.md: ########## @@ -1801,6 +1807,65 @@ If a delete column in an equality delete file is later dropped from the table, i Manifests hold the same statistics for delete files and data files. For delete files, the metrics describe the values that were deleted. +### Column Files + +In v4 and later, a data file or leaf manifest may store fields in column files listed in [`column_files`](#column-file-fields). The data file or leaf manifest whose `column_files` lists a column file is that column file's _base file_. + +A column file can use any supported Iceberg file format and must have the same row count as its base file. Its rows are aligned with the base file's rows by position, including deleted rows. + +A column file stores fields identified by field ID. If a field's ID is in a column file's `field_ids`, that column file is _responsible_ for the field and all fields nested in it. A field ID may be in the `field_ids` of at most one of a base file's column files, and `_row_id` must not be in any column file's `field_ids`. For example, a column file with `field_ids = [3, 5]`, where both fields are primitive, is responsible for fields 3 and 5. + +List, map, and file type fields are identified by their own ID. IDs of fields nested in these types, such as a list's element ID or a map's key and value IDs, must not be in `field_ids`. For example, for `8: tags list<9: string>`, `field_ids` may have 8 but not 9. + +A field nested in a struct may have its ID in another column file's `field_ids`. That column file is then responsible for the nested field instead. For example, for `4: address struct<5: street, 6: city>`, if one column file's `field_ids` is `[4]` and another's is `[5]`, the second file is responsible for `street` and the first for `address` and `city`. Review Comment: "A field nested in a struct may have its ID in another column file's `field_ids`" Reading this sentence doesn't make it clear what we mean by "another". Then the example below explains it. Don't we want to say that when a struct's ID is in a column file, a nested field's ID may be in another column file? ########## format/spec.md: ########## @@ -1801,6 +1807,65 @@ If a delete column in an equality delete file is later dropped from the table, i Manifests hold the same statistics for delete files and data files. For delete files, the metrics describe the values that were deleted. +### Column Files + +In v4 and later, a data file or leaf manifest may store fields in column files listed in [`column_files`](#column-file-fields). The data file or leaf manifest whose `column_files` lists a column file is that column file's _base file_. + +A column file can use any supported Iceberg file format and must have the same row count as its base file. Its rows are aligned with the base file's rows by position, including deleted rows. + +A column file stores fields identified by field ID. If a field's ID is in a column file's `field_ids`, that column file is _responsible_ for the field and all fields nested in it. A field ID may be in the `field_ids` of at most one of a base file's column files, and `_row_id` must not be in any column file's `field_ids`. For example, a column file with `field_ids = [3, 5]`, where both fields are primitive, is responsible for fields 3 and 5. + +List, map, and file type fields are identified by their own ID. IDs of fields nested in these types, such as a list's element ID or a map's key and value IDs, must not be in `field_ids`. For example, for `8: tags list<9: string>`, `field_ids` may have 8 but not 9. + +A field nested in a struct may have its ID in another column file's `field_ids`. That column file is then responsible for the nested field instead. For example, for `4: address struct<5: street, 6: city>`, if one column file's `field_ids` is `[4]` and another's is `[5]`, the second file is responsible for `street` and the first for `address` and `city`. + +The base file is responsible for every field that no column file is responsible for. Every file that is responsible for part of a struct, including the base file, must store the same null state for that struct in each row. For example, for `4: address struct<5: street, 6: city>`, if one column file's `field_ids` is `[4]` and another's is `[5]`, and the first stores `address` as null in a row, the second must also store `address` as null in that row. Review Comment: This seems 2 different rules: 1) base file responsibility 2) another rule for structs Can you split these, and move 2) closer to structs rules? ########## format/spec.md: ########## @@ -1434,11 +1437,12 @@ When expiring snapshots, retention policies in table and snapshot references are #### Deleting Files -A file may be deleted from the file system when the snapshot in which it was deleted is garbage collected, assuming that the file is not live in any remaining snapshot [1]. +A file may be deleted from the file system when the snapshot in which it was deleted is garbage collected, assuming that the file is not live in any remaining snapshot [1], [2]. Notes: 1. Technically, data files can be deleted when the last snapshot that contains the file as "live" data is garbage collected. But this is harder to detect and requires finding the diff of multiple snapshots. When all snapshots are ancestors of a single branch, it is easier to track what files are deleted in a snapshot and delete them when that snapshot expires. It is not recommended to add a deleted file back to a table. Adding a deleted file can lead to edge cases where incremental deletes can break table snapshots. +2. In v4, column files and deletion vectors are tracked in data file metadata and are not removed using a DELETED manifest entry. These files may be deleted when referenced by a REPLACED entry and not its corresponding MODIFIED entry. Review Comment: "In v4," Shouldn't we avoid using V4 in such text? What about V5 and above? How about this? "Column files and deletion vectors tracked by data file metadata are not removed using a DELETED manifest entry." Might also add "tracked colocated by data file metadata" ########## format/spec.md: ########## @@ -1801,6 +1807,65 @@ If a delete column in an equality delete file is later dropped from the table, i Manifests hold the same statistics for delete files and data files. For delete files, the metrics describe the values that were deleted. +### Column Files + +In v4 and later, a data file or leaf manifest may store fields in column files listed in [`column_files`](#column-file-fields). The data file or leaf manifest whose `column_files` lists a column file is that column file's _base file_. + +A column file can use any supported Iceberg file format and must have the same row count as its base file. Its rows are aligned with the base file's rows by position, including deleted rows. + +A column file stores fields identified by field ID. If a field's ID is in a column file's `field_ids`, that column file is _responsible_ for the field and all fields nested in it. A field ID may be in the `field_ids` of at most one of a base file's column files, and `_row_id` must not be in any column file's `field_ids`. For example, a column file with `field_ids = [3, 5]`, where both fields are primitive, is responsible for fields 3 and 5. + +List, map, and file type fields are identified by their own ID. IDs of fields nested in these types, such as a list's element ID or a map's key and value IDs, must not be in `field_ids`. For example, for `8: tags list<9: string>`, `field_ids` may have 8 but not 9. + +A field nested in a struct may have its ID in another column file's `field_ids`. That column file is then responsible for the nested field instead. For example, for `4: address struct<5: street, 6: city>`, if one column file's `field_ids` is `[4]` and another's is `[5]`, the second file is responsible for `street` and the first for `address` and `city`. + +The base file is responsible for every field that no column file is responsible for. Every file that is responsible for part of a struct, including the base file, must store the same null state for that struct in each row. For example, for `4: address struct<5: street, 6: city>`, if one column file's `field_ids` is `[4]` and another's is `[5]`, and the first stores `address` as null in a row, the second must also store `address` as null in that row. + +#### Writing Column Files + +A column file stores a value for every row of its base file, including rows whose values did not change. Values for deleted rows should be null. A column file may write a field as optional even if that field is required in the table schema. + +In addition to the requirements above, writers adding column files must follow these rules. A rule applies if its condition holds for at least one row where every struct that the field is nested in is non-null after the update. + +- The added column files must be responsible for each non-struct field whose value changes. +- If a struct changes between null and non-null, the added column files must be responsible for the struct and for every field nested in it. + +#### Reading Column Files + +Readers must read each field from the file responsible for it, which is the first of: + +1. The column file whose `field_ids` has the field's ID. +2. The file responsible for the field's parent. +3. The base file. + +Readers must ignore all other fields in a column file. Null values in a column file may represent deleted rows. + +A data file and its column files are read using [Column Projection](#column-projection). + +If a struct is null in a row, every field nested in it is null in that row. A reader may take the struct's null state from any file responsible for part of it. + +#### Tracking Column File Changes + +When a writer adds column files to a data file, the writer must produce a MODIFIED entry and a REPLACED entry as described in [Updating Tracking Metadata](#updating-tracking-metadata). The MODIFIED entry holds the new metadata and records the snapshot that added the column files in `modified_snapshot_id`. The REPLACED entry holds the previous metadata and may be produced in place using the leaf manifest's `manifest_info.dv`. The writer may write the two entries to different manifests. + +When a writer adds column files to a leaf manifest itself, replacing fields of the entries it tracks such as their `deletion_vector`, the writer must produce a MODIFIED entry and a REPLACED entry for the leaf manifest in the root manifest. The same commit may also change the leaf manifest's `manifest_info.dv`. + +Adding column files to a data file or a leaf manifest changes its MODIFIED entry as follows: + +- `tracking`: + - `status` must be MODIFIED. Review Comment: "Adding column files to ... changes its MODIFIED entry as follows: `status` must be MODIFIED." The MODIFIED status seems redundant. Maybe the introducing sense could be more general: "When adding column files to a data file or a leaf manifest, the created entry must contain these changes compared to the REPLACED entry:" ########## format/spec.md: ########## Review Comment: I'd revisit this comment: I think in terms of the ADP it not just enables column updates, but in general storing column values in column files. A writer can write data split into multiple files right ahead with this design, it's not just column updates that leverage this. ########## format/spec.md: ########## @@ -1801,6 +1807,65 @@ If a delete column in an equality delete file is later dropped from the table, i Manifests hold the same statistics for delete files and data files. For delete files, the metrics describe the values that were deleted. +### Column Files + +In v4 and later, a data file or leaf manifest may store fields in column files listed in [`column_files`](#column-file-fields). The data file or leaf manifest whose `column_files` lists a column file is that column file's _base file_. + +A column file can use any supported Iceberg file format and must have the same row count as its base file. Its rows are aligned with the base file's rows by position, including deleted rows. + +A column file stores fields identified by field ID. If a field's ID is in a column file's `field_ids`, that column file is _responsible_ for the field and all fields nested in it. A field ID may be in the `field_ids` of at most one of a base file's column files, and `_row_id` must not be in any column file's `field_ids`. For example, a column file with `field_ids = [3, 5]`, where both fields are primitive, is responsible for fields 3 and 5. + +List, map, and file type fields are identified by their own ID. IDs of fields nested in these types, such as a list's element ID or a map's key and value IDs, must not be in `field_ids`. For example, for `8: tags list<9: string>`, `field_ids` may have 8 but not 9. + +A field nested in a struct may have its ID in another column file's `field_ids`. That column file is then responsible for the nested field instead. For example, for `4: address struct<5: street, 6: city>`, if one column file's `field_ids` is `[4]` and another's is `[5]`, the second file is responsible for `street` and the first for `address` and `city`. + +The base file is responsible for every field that no column file is responsible for. Every file that is responsible for part of a struct, including the base file, must store the same null state for that struct in each row. For example, for `4: address struct<5: street, 6: city>`, if one column file's `field_ids` is `[4]` and another's is `[5]`, and the first stores `address` as null in a row, the second must also store `address` as null in that row. + +#### Writing Column Files + +A column file stores a value for every row of its base file, including rows whose values did not change. Values for deleted rows should be null. A column file may write a field as optional even if that field is required in the table schema. + +In addition to the requirements above, writers adding column files must follow these rules. A rule applies if its condition holds for at least one row where every struct that the field is nested in is non-null after the update. + +- The added column files must be responsible for each non-struct field whose value changes. +- If a struct changes between null and non-null, the added column files must be responsible for the struct and for every field nested in it. + +#### Reading Column Files + +Readers must read each field from the file responsible for it, which is the first of: + +1. The column file whose `field_ids` has the field's ID. +2. The file responsible for the field's parent. +3. The base file. + +Readers must ignore all other fields in a column file. Null values in a column file may represent deleted rows. + +A data file and its column files are read using [Column Projection](#column-projection). + +If a struct is null in a row, every field nested in it is null in that row. A reader may take the struct's null state from any file responsible for part of it. + +#### Tracking Column File Changes + +When a writer adds column files to a data file, the writer must produce a MODIFIED entry and a REPLACED entry as described in [Updating Tracking Metadata](#updating-tracking-metadata). The MODIFIED entry holds the new metadata and records the snapshot that added the column files in `modified_snapshot_id`. The REPLACED entry holds the previous metadata and may be produced in place using the leaf manifest's `manifest_info.dv`. The writer may write the two entries to different manifests. + +When a writer adds column files to a leaf manifest itself, replacing fields of the entries it tracks such as their `deletion_vector`, the writer must produce a MODIFIED entry and a REPLACED entry for the leaf manifest in the root manifest. The same commit may also change the leaf manifest's `manifest_info.dv`. + +Adding column files to a data file or a leaf manifest changes its MODIFIED entry as follows: + +- `tracking`: + - `status` must be MODIFIED. + - `modified_snapshot_id` must be the ID of the snapshot that adds the column files. Review Comment: This is redundant with the first paragraph in "Tracking Column File Changes". I propose to drop the sentence there and keep it here. ########## format/spec.md: ########## @@ -1801,6 +1807,65 @@ If a delete column in an equality delete file is later dropped from the table, i Manifests hold the same statistics for delete files and data files. For delete files, the metrics describe the values that were deleted. +### Column Files + +In v4 and later, a data file or leaf manifest may store fields in column files listed in [`column_files`](#column-file-fields). The data file or leaf manifest whose `column_files` lists a column file is that column file's _base file_. + +A column file can use any supported Iceberg file format and must have the same row count as its base file. Its rows are aligned with the base file's rows by position, including deleted rows. + +A column file stores fields identified by field ID. If a field's ID is in a column file's `field_ids`, that column file is _responsible_ for the field and all fields nested in it. A field ID may be in the `field_ids` of at most one of a base file's column files, and `_row_id` must not be in any column file's `field_ids`. For example, a column file with `field_ids = [3, 5]`, where both fields are primitive, is responsible for fields 3 and 5. + +List, map, and file type fields are identified by their own ID. IDs of fields nested in these types, such as a list's element ID or a map's key and value IDs, must not be in `field_ids`. For example, for `8: tags list<9: string>`, `field_ids` may have 8 but not 9. + +A field nested in a struct may have its ID in another column file's `field_ids`. That column file is then responsible for the nested field instead. For example, for `4: address struct<5: street, 6: city>`, if one column file's `field_ids` is `[4]` and another's is `[5]`, the second file is responsible for `street` and the first for `address` and `city`. + +The base file is responsible for every field that no column file is responsible for. Every file that is responsible for part of a struct, including the base file, must store the same null state for that struct in each row. For example, for `4: address struct<5: street, 6: city>`, if one column file's `field_ids` is `[4]` and another's is `[5]`, and the first stores `address` as null in a row, the second must also store `address` as null in that row. Review Comment: "`4: address struct<5: street, 6: city>`, if one column file's `field_ids` is `[4]` and another's is `[5]`" Can we create such a column file that has [4] only? Would that mean we create a Parquet file that has a single struct field in the schema, without struct members? I don't think that's feasible with Parquet. Or is [4] a result of initially having [4, 5], but [5] was covered by a later column files and was removed from the field IDs here? Sorry if this is trivial, I don't entirely see how this works with structs. ########## format/spec.md: ########## @@ -1801,6 +1807,65 @@ If a delete column in an equality delete file is later dropped from the table, i Manifests hold the same statistics for delete files and data files. For delete files, the metrics describe the values that were deleted. +### Column Files + +In v4 and later, a data file or leaf manifest may store fields in column files listed in [`column_files`](#column-file-fields). The data file or leaf manifest whose `column_files` lists a column file is that column file's _base file_. + +A column file can use any supported Iceberg file format and must have the same row count as its base file. Its rows are aligned with the base file's rows by position, including deleted rows. + +A column file stores fields identified by field ID. If a field's ID is in a column file's `field_ids`, that column file is _responsible_ for the field and all fields nested in it. A field ID may be in the `field_ids` of at most one of a base file's column files, and `_row_id` must not be in any column file's `field_ids`. For example, a column file with `field_ids = [3, 5]`, where both fields are primitive, is responsible for fields 3 and 5. + +List, map, and file type fields are identified by their own ID. IDs of fields nested in these types, such as a list's element ID or a map's key and value IDs, must not be in `field_ids`. For example, for `8: tags list<9: string>`, `field_ids` may have 8 but not 9. + +A field nested in a struct may have its ID in another column file's `field_ids`. That column file is then responsible for the nested field instead. For example, for `4: address struct<5: street, 6: city>`, if one column file's `field_ids` is `[4]` and another's is `[5]`, the second file is responsible for `street` and the first for `address` and `city`. + +The base file is responsible for every field that no column file is responsible for. Every file that is responsible for part of a struct, including the base file, must store the same null state for that struct in each row. For example, for `4: address struct<5: street, 6: city>`, if one column file's `field_ids` is `[4]` and another's is `[5]`, and the first stores `address` as null in a row, the second must also store `address` as null in that row. + +#### Writing Column Files + +A column file stores a value for every row of its base file, including rows whose values did not change. Values for deleted rows should be null. A column file may write a field as optional even if that field is required in the table schema. + +In addition to the requirements above, writers adding column files must follow these rules. A rule applies if its condition holds for at least one row where every struct that the field is nested in is non-null after the update. Review Comment: I found this hard to understand. I did some itterations on this with my AI-friend, how about this? "In addition to the requirements above, writers adding column files must follow these rules. When checking a rule for a field, consider only rows where none of the structs that contain that field is null after the update. - The added column files must be responsible for each non-struct field whose value changes in at least one such row. - If a struct changes between null and non-null in at least one such row, the added column files must be responsible for the struct and for every field nested in it." -- 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]
