anuragmantri commented on code in PR #16425:
URL: https://github.com/apache/iceberg/pull/16425#discussion_r4670589417


##########
format/spec.md:
##########
@@ -1801,6 +1805,51 @@ 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
+
+Starting in v4, a data file or v4 leaf manifest may store fields in column 
files listed in [`column_files`](#column-file-fields). A column file can use 
any supported Iceberg file format and must have rows that align with the file 
it modifies.

Review Comment:
   Ryan suggested keeping one "In v4 and later" at the start of the Column 
Files section, so I added it back there



##########
format/spec.md:
##########
@@ -88,7 +88,7 @@ This table format tracks individual data files in a table 
instead of directories
 
 Table state is maintained in metadata files. All changes to table state create 
a new metadata file and replace the old metadata with an atomic swap. The table 
metadata file tracks the table schema, partitioning config, custom properties, 
and snapshots of the table contents. A snapshot represents the state of a table 
at some time and is used to access the complete set of data files in the table.
 
-Data files in snapshots are tracked by one or more manifest files that contain 
a row for each data file in the table, the file's partition data, an optional 
colocated deletion vector (v4), and its metrics. The data in a snapshot is the 
union of all live files in its manifests; each live file may only appear once 
(see [Content file uniqueness](#content-file-uniqueness)). Manifest files are 
reused across snapshots to avoid rewriting metadata that is slow-changing. 
Manifests can track data files with any subset of a table and are not 
associated with partitions.
+Data files in snapshots are tracked by one or more manifest files that contain 
a row for each data file in the table, the file's partition data, an optional 
colocated deletion vector and optional column files (v4), and its metrics. The 
data in a snapshot is the union of all live files in its manifests; each live 
file may only appear once (see [Content file 
uniqueness](#content-file-uniqueness)). Manifest files are reused across 
snapshots to avoid rewriting metadata that is slow-changing. Manifests can 
track data files with any subset of a table and are not associated with 
partitions.

Review Comment:
   Ryan suggested removing the list of what a manifest row stores, so the v4 
wording is also removed. 



##########
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. A column file removed from `column_files` is not recorded with a DELETED 
entry. It may be deleted from the file system when the last snapshot that still 
references it, including on a REPLACED entry, is garbage collected. The same 
rule applies to a deletion vector that remains only on a REPLACED entry.

Review Comment:
    Ryan's suggestion was also this, it's done. 



##########
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 and must not change unless a column file is 
added to a data file. 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.

Review Comment:
   Applied, with two small changes: "when a column file modifies its rows", so 
leaf manifests keep their sequence number, and I kept "must not change 
otherwise".



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.

Review Comment:
   I removed the list of valid IDs, since `Reading` section now states the 
order to read fields in. I kept one sentence that `_row_id` must not be in 
`field_ids`, since row IDs never change.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.

Review Comment:
   Not anymore. Listing a struct makes that file responsible for everything 
inside it, so replacing a whole struct is just its ID.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.

Review Comment:
   Removed. The list/map and struct rules now live only in the top section.



##########
format/spec.md:
##########
@@ -804,7 +807,7 @@ Each manifest type contains the following content:
 | v1-v3   | Data manifest   | Data files                                      
| Avro |
 | v2-v3   | Delete manifest | Delete files                                    
| Avro |
 | v4      | Root manifest   | Leaf manifests, data files, or v1-v3 manifests  
| Parquet |
-| v4      | Leaf manifest   | Data files and their colocated deletion vectors 
| Parquet |
+| v4      | Leaf manifest   | Data files, with their colocated deletion 
vectors and column files | Parquet |

Review Comment:
   Applied, thanks.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.
+
+The `tracking` fields of the MODIFIED entry are set as described in [Updating 
Tracking Metadata](#updating-tracking-metadata) and [Sequence Number 
Inheritance](#sequence-number-inheritance), and `tracking.snapshot_id` must be 
the previous entry's (inherited) snapshot ID. The fields of the MODIFIED entry 
outside `tracking` must match the previous entry, except for the following:
+
+- `partition`:
+    - For a data file, an added column file's `field_ids` may have the ID of a 
source field of the data file's partition spec, or of a struct that one is 
nested in, only if all live rows share the same partition values after the 
update. `partition` must be set to those values.
+- `sort_order_id`:
+    - For a data file, if an added column file lists a field in the data 
file's sort order, or a struct that one is nested in, `sort_order_id` must be 
null.
+- `content_stats`:
+    - Stats for a field listed in an added column file, and for its nested 
fields, must be recomputed or omitted.
+    - For a leaf manifest, stats that summarize a listed field must be 
recomputed or omitted.
+- `tight_stats`:
+    - If `tight_stats` is true, `content_stats` must be tight for the live 
rows after the update (see [Stats Tightness](#stats-tightness)).
+- `deletion_vector`:
+    - For a data file, every delete that applied to it before the column files 
were added must be written into the MODIFIED entry's `deletion_vector`.
+- `column_files`:
+    - Each field listed in an added column file must be removed from the 
`field_ids` of the previous entry's column files. A column file with no 
remaining `field_ids` must be removed.
+    - For a data file, one of the added column files must have the 
`_last_updated_sequence_number` ID in its `field_ids`, so that rows changed by 
the added column files get a new `_last_updated_sequence_number`. In that 
column file:

Review Comment:
   Removed here. However Ryan asked to add why in the `Row Lineage` so I added 
it there.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.

Review Comment:
   I reworded so `field_ids` says which fields a column file is responsible 
for, not what it stores. A listed field now covers the fields nested in it, as 
you suggested in the struct comment.



##########
format/spec.md:
##########
@@ -88,7 +88,7 @@ This table format tracks individual data files in a table 
instead of directories
 
 Table state is maintained in metadata files. All changes to table state create 
a new metadata file and replace the old metadata with an atomic swap. The table 
metadata file tracks the table schema, partitioning config, custom properties, 
and snapshots of the table contents. A snapshot represents the state of a table 
at some time and is used to access the complete set of data files in the table.
 
-Data files in snapshots are tracked by one or more manifest files that contain 
a row for each data file in the table, the file's partition data, an optional 
colocated deletion vector (v4), and its metrics. The data in a snapshot is the 
union of all live files in its manifests; each live file may only appear once 
(see [Content file uniqueness](#content-file-uniqueness)). Manifest files are 
reused across snapshots to avoid rewriting metadata that is slow-changing. 
Manifests can track data files with any subset of a table and are not 
associated with partitions.
+Data files in snapshots are tracked by one or more manifest files that contain 
a row for each data file in the table, the file's partition data, its metrics, 
and, starting in v4, an optional colocated deletion vector and optional column 
files. The data in a snapshot is the union of all live files in its manifests; 
each live file may only appear once (see [Content file 
uniqueness](#content-file-uniqueness)). Manifest files are reused across 
snapshots to avoid rewriting metadata that is slow-changing. Manifests can 
track data files with any subset of a table and are not associated with 
partitions.

Review Comment:
   Applied. Thanks.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.

Review Comment:
   I replaced it with your suggestion. Now the rule is that if a struct changes 
between null and non-null, the new column files must be responsible for the 
struct and everything nested in it. That's what keeps the null states matching. 
If another column file still covered a child, it would disagree about the 
struct's nullity which is invalid.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.
+
+The `tracking` fields of the MODIFIED entry are set as described in [Updating 
Tracking Metadata](#updating-tracking-metadata) and [Sequence Number 
Inheritance](#sequence-number-inheritance), and `tracking.snapshot_id` must be 
the previous entry's (inherited) snapshot ID. The fields of the MODIFIED entry 
outside `tracking` must match the previous entry, except for the following:
+
+- `partition`:

Review Comment:
   Agreed. I replaced the partition, sort and stats rules with one requirement 
that the rest of the entry's metadata stays consistent with the data after the 
update.



##########
format/spec.md:
##########
@@ -1748,7 +1751,7 @@ 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. 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. Adding column files 
to a data file sets its data sequence number to that snapshot's sequence 
number, so existing equality delete files no longer apply to it (see [Writing 
Column Files](#writing-column-files)).

Review Comment:
   Applied, thanks.



##########
format/spec.md:
##########
@@ -157,6 +157,7 @@ Version 4 of the Iceberg spec adds support for relative 
locations in metadata, e
 * **Delete manifest** -- A file that lists delete files to be associated with 
data files at planning time.
 * **Data file** -- A file that contains rows of a table.
 * **Delete file** -- A file that encodes rows of a table that are deleted by 
position or data values.
+* **Column file** -- (v4+) A file that stores the values of one or more fields 
for a data file or a leaf manifest.

Review Comment:
   Applied Ryan's definition, thanks. For the Manifests table, Ryan suggested 
listing only data files, since colocated DVs and column files can also be on 
data files in the root manifest, so I took that instead.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.
+
+The `tracking` fields of the MODIFIED entry are set as described in [Updating 
Tracking Metadata](#updating-tracking-metadata) and [Sequence Number 
Inheritance](#sequence-number-inheritance), and `tracking.snapshot_id` must be 
the previous entry's (inherited) snapshot ID. The fields of the MODIFIED entry 
outside `tracking` must match the previous entry, except for the following:
+
+- `partition`:
+    - For a data file, an added column file's `field_ids` may have the ID of a 
source field of the data file's partition spec, or of a struct that one is 
nested in, only if all live rows share the same partition values after the 
update. `partition` must be set to those values.
+- `sort_order_id`:
+    - For a data file, if an added column file lists a field in the data 
file's sort order, or a struct that one is nested in, `sort_order_id` must be 
null.
+- `content_stats`:
+    - Stats for a field listed in an added column file, and for its nested 
fields, must be recomputed or omitted.
+    - For a leaf manifest, stats that summarize a listed field must be 
recomputed or omitted.
+- `tight_stats`:
+    - If `tight_stats` is true, `content_stats` must be tight for the live 
rows after the update (see [Stats Tightness](#stats-tightness)).
+- `deletion_vector`:
+    - For a data file, every delete that applied to it before the column files 
were added must be written into the MODIFIED entry's `deletion_vector`.
+- `column_files`:
+    - Each field listed in an added column file must be removed from the 
`field_ids` of the previous entry's column files. A column file with no 
remaining `field_ids` must be removed.
+    - For a data file, one of the added column files must have the 
`_last_updated_sequence_number` ID in its `field_ids`, so that rows changed by 
the added column files get a new `_last_updated_sequence_number`. In that 
column file:
+        - If the added column files change the row, 
`_last_updated_sequence_number` must be set to `null` (so that the sequence 
number of the snapshot that added the column files replaces the current value).
+        - If the added column files do not change the row and the row is not 
deleted, `_last_updated_sequence_number` must be copied to the new column file. 
A null value must be replaced with the data sequence number a reader of the 
previous entry would assign.
+
+#### Reading Column Files
+
+Each projected field, including each field nested in a projected field, must 
be read from the column file whose `field_ids` has its ID. A field nested in a 
list or map is read with that list or map. Other projected fields are read from 
the base file, using [Column Projection](#column-projection) for a data file. A 
column file of a data file is also read using [Column 
Projection](#column-projection).

Review Comment:
   Done, in the `Reading` section.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.

Review Comment:
   The lead sentance now says these rules are in addition to the requirements 
above.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.
+
+The `tracking` fields of the MODIFIED entry are set as described in [Updating 
Tracking Metadata](#updating-tracking-metadata) and [Sequence Number 
Inheritance](#sequence-number-inheritance), and `tracking.snapshot_id` must be 
the previous entry's (inherited) snapshot ID. The fields of the MODIFIED entry 
outside `tracking` must match the previous entry, except for the following:
+
+- `partition`:
+    - For a data file, an added column file's `field_ids` may have the ID of a 
source field of the data file's partition spec, or of a struct that one is 
nested in, only if all live rows share the same partition values after the 
update. `partition` must be set to those values.
+- `sort_order_id`:
+    - For a data file, if an added column file lists a field in the data 
file's sort order, or a struct that one is nested in, `sort_order_id` must be 
null.
+- `content_stats`:
+    - Stats for a field listed in an added column file, and for its nested 
fields, must be recomputed or omitted.
+    - For a leaf manifest, stats that summarize a listed field must be 
recomputed or omitted.
+- `tight_stats`:
+    - If `tight_stats` is true, `content_stats` must be tight for the live 
rows after the update (see [Stats Tightness](#stats-tightness)).
+- `deletion_vector`:
+    - For a data file, every delete that applied to it before the column files 
were added must be written into the MODIFIED entry's `deletion_vector`.
+- `column_files`:
+    - Each field listed in an added column file must be removed from the 
`field_ids` of the previous entry's column files. A column file with no 
remaining `field_ids` must be removed.
+    - For a data file, one of the added column files must have the 
`_last_updated_sequence_number` ID in its `field_ids`, so that rows changed by 
the added column files get a new `_last_updated_sequence_number`. In that 
column file:
+        - If the added column files change the row, 
`_last_updated_sequence_number` must be set to `null` (so that the sequence 
number of the snapshot that added the column files replaces the current value).
+        - If the added column files do not change the row and the row is not 
deleted, `_last_updated_sequence_number` must be copied to the new column file. 
A null value must be replaced with the data sequence number a reader of the 
previous entry would assign.
+
+#### Reading Column Files
+
+Each projected field, including each field nested in a projected field, must 
be read from the column file whose `field_ids` has its ID. A field nested in a 
list or map is read with that list or map. Other projected fields are read from 
the base file, using [Column Projection](#column-projection) for a data file. A 
column file of a data file is also read using [Column 
Projection](#column-projection).
+
+If a struct is null in a row, every field nested in it is null in that row, 
including a field read from a column file.
+
+A column file and its base file are aligned by row position before the 
attached deletion vector is applied. The scan schema must be used for field 
types and nullability. Null values in a column file may represent deleted rows.

Review Comment:
   The scan schema sentence was meant to say that readers take a field's type 
and whether it's required from the table schema, not from the column file's own 
schema. [Column 
Projection](https://github.com/apache/iceberg/blob/main/format/spec.md#column-projection)
 already covers that, so I removed it.
   
   The alignment requirement is also now moved to top section.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.

Review Comment:
   There are only two now, please check the new rules. 



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.
+
+The `tracking` fields of the MODIFIED entry are set as described in [Updating 
Tracking Metadata](#updating-tracking-metadata) and [Sequence Number 
Inheritance](#sequence-number-inheritance), and `tracking.snapshot_id` must be 
the previous entry's (inherited) snapshot ID. The fields of the MODIFIED entry 
outside `tracking` must match the previous entry, except for the following:
+
+- `partition`:
+    - For a data file, an added column file's `field_ids` may have the ID of a 
source field of the data file's partition spec, or of a struct that one is 
nested in, only if all live rows share the same partition values after the 
update. `partition` must be set to those values.
+- `sort_order_id`:
+    - For a data file, if an added column file lists a field in the data 
file's sort order, or a struct that one is nested in, `sort_order_id` must be 
null.
+- `content_stats`:
+    - Stats for a field listed in an added column file, and for its nested 
fields, must be recomputed or omitted.
+    - For a leaf manifest, stats that summarize a listed field must be 
recomputed or omitted.
+- `tight_stats`:
+    - If `tight_stats` is true, `content_stats` must be tight for the live 
rows after the update (see [Stats Tightness](#stats-tightness)).
+- `deletion_vector`:
+    - For a data file, every delete that applied to it before the column files 
were added must be written into the MODIFIED entry's `deletion_vector`.
+- `column_files`:
+    - Each field listed in an added column file must be removed from the 
`field_ids` of the previous entry's column files. A column file with no 
remaining `field_ids` must be removed.

Review Comment:
   Applied, thanks.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.

Review Comment:
   Removed that sentence.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.
+
+The `tracking` fields of the MODIFIED entry are set as described in [Updating 
Tracking Metadata](#updating-tracking-metadata) and [Sequence Number 
Inheritance](#sequence-number-inheritance), and `tracking.snapshot_id` must be 
the previous entry's (inherited) snapshot ID. The fields of the MODIFIED entry 
outside `tracking` must match the previous entry, except for the following:
+
+- `partition`:
+    - For a data file, an added column file's `field_ids` may have the ID of a 
source field of the data file's partition spec, or of a struct that one is 
nested in, only if all live rows share the same partition values after the 
update. `partition` must be set to those values.
+- `sort_order_id`:
+    - For a data file, if an added column file lists a field in the data 
file's sort order, or a struct that one is nested in, `sort_order_id` must be 
null.
+- `content_stats`:
+    - Stats for a field listed in an added column file, and for its nested 
fields, must be recomputed or omitted.
+    - For a leaf manifest, stats that summarize a listed field must be 
recomputed or omitted.
+- `tight_stats`:
+    - If `tight_stats` is true, `content_stats` must be tight for the live 
rows after the update (see [Stats Tightness](#stats-tightness)).
+- `deletion_vector`:
+    - For a data file, every delete that applied to it before the column files 
were added must be written into the MODIFIED entry's `deletion_vector`.
+- `column_files`:
+    - Each field listed in an added column file must be removed from the 
`field_ids` of the previous entry's column files. A column file with no 
remaining `field_ids` must be removed.
+    - For a data file, one of the added column files must have the 
`_last_updated_sequence_number` ID in its `field_ids`, so that rows changed by 
the added column files get a new `_last_updated_sequence_number`. In that 
column file:
+        - If the added column files change the row, 
`_last_updated_sequence_number` must be set to `null` (so that the sequence 
number of the snapshot that added the column files replaces the current value).
+        - If the added column files do not change the row and the row is not 
deleted, `_last_updated_sequence_number` must be copied to the new column file. 
A null value must be replaced with the data sequence number a reader of the 
previous entry would assign.

Review Comment:
   I simplified it to one sentence. I said "the row's current value" rather 
than "from the base file", because after an earlier update the value can be in 
a previous column file.



##########
format/spec.md:
##########
@@ -530,6 +531,8 @@ When an existing row is moved to a different data file for 
any reason, writers s
 
 Engines may model operations as deleting/inserting rows or as modifications to 
rows that preserve row ids.
 
+When column files are added to a data file, `_last_updated_sequence_number` is 
handled as described in [Writing Column Files](#writing-column-files).

Review Comment:
   I inlined it, with one addition: rows the column files don't change copy 
their current value, otherwise they'd inherit the new sequence number too. 
`_row_id` can't be in `field_ids`, which Column Files now says, and row IDs 
don't change because the MODIFIED entry keeps `first_row_id`.



##########
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. A column file removed from `column_files` is not recorded with a DELETED 
entry. It may be deleted from the file system when the last snapshot that still 
references it, including on a REPLACED entry, is garbage collected. The same 
rule applies to a deletion vector that remains only on a REPLACED entry.

Review Comment:
   Done.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.

Review Comment:
   Thanks, I reworked the section along these lines.
   - The top section now only describes column files. If a field's ID is in a 
column file's field_ids, that file is responsible for the field and everything 
nested in it.
   - List, map, variant, and file type fields are identified only by their own 
ID, and IDs nested in them must not be in field_ids.
   - Every file responsible for part of a struct, including the base file, must 
store the same null state for that struct. After our offline discussion, 
matching nullity is the better choice, because a reader can then take a 
struct's null state from whichever file it already reads.
   - The writer rules, the read order (the column file that lists the field, 
then the file responsible for its parent, then the base file), and tracking 
changes are each in their own short section.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.
+
+The `tracking` fields of the MODIFIED entry are set as described in [Updating 
Tracking Metadata](#updating-tracking-metadata) and [Sequence Number 
Inheritance](#sequence-number-inheritance), and `tracking.snapshot_id` must be 
the previous entry's (inherited) snapshot ID. The fields of the MODIFIED entry 
outside `tracking` must match the previous entry, except for the following:
+
+- `partition`:
+    - For a data file, an added column file's `field_ids` may have the ID of a 
source field of the data file's partition spec, or of a struct that one is 
nested in, only if all live rows share the same partition values after the 
update. `partition` must be set to those values.
+- `sort_order_id`:
+    - For a data file, if an added column file lists a field in the data 
file's sort order, or a struct that one is nested in, `sort_order_id` must be 
null.
+- `content_stats`:
+    - Stats for a field listed in an added column file, and for its nested 
fields, must be recomputed or omitted.
+    - For a leaf manifest, stats that summarize a listed field must be 
recomputed or omitted.
+- `tight_stats`:
+    - If `tight_stats` is true, `content_stats` must be tight for the live 
rows after the update (see [Stats Tightness](#stats-tightness)).
+- `deletion_vector`:
+    - For a data file, every delete that applied to it before the column files 
were added must be written into the MODIFIED entry's `deletion_vector`.
+- `column_files`:
+    - Each field listed in an added column file must be removed from the 
`field_ids` of the previous entry's column files. A column file with no 
remaining `field_ids` must be removed.
+    - For a data file, one of the added column files must have the 
`_last_updated_sequence_number` ID in its `field_ids`, so that rows changed by 
the added column files get a new `_last_updated_sequence_number`. In that 
column file:
+        - If the added column files change the row, 
`_last_updated_sequence_number` must be set to `null` (so that the sequence 
number of the snapshot that added the column files replaces the current value).
+        - If the added column files do not change the row and the row is not 
deleted, `_last_updated_sequence_number` must be copied to the new column file. 
A null value must be replaced with the data sequence number a reader of the 
previous entry would assign.
+
+#### Reading Column Files
+
+Each projected field, including each field nested in a projected field, must 
be read from the column file whose `field_ids` has its ID. A field nested in a 
list or map is read with that list or map. Other projected fields are read from 
the base file, using [Column Projection](#column-projection) for a data file. A 
column file of a data file is also read using [Column 
Projection](#column-projection).
+
+If a struct is null in a row, every field nested in it is null in that row, 
including a field read from a column file.
+
+A column file and its base file are aligned by row position before the 
attached deletion vector is applied. The scan schema must be used for field 
types and nullability. Null values in a column file may represent deleted rows.
+
+#### Column file example
+
+This example demonstrates which field IDs a column file must have in its 
`field_ids`, using this schema and one row of a data file. Unless a row says 
otherwise, that row in the base file is `customer = {name: …, address: {street: 
'1 Elm', city: 'Austin'}}`. Column files are named `column_file_1`, 
`column_file_2`, and so on. The `_last_updated_sequence_number` ID that each 
update also adds to `field_ids` is left out.
+
+```
+2: optional struct customer {
+  3: optional string name;
+  4: optional struct address {
+    5: optional string street;
+    6: optional string city;
+  }
+}
+8: optional list<string> tags; // element field ID 9
+```
+
+| Row before the update | Update | Valid column files | Invalid column files | 
Notes |
+|---|---|---|---|---|
+| `customer` is null | `SET name = 'andrew'` | `column_file_1` with `field_ids 
= [2, 3, 4]`, and `address` null | `column_file_1` with `field_ids = [3]` | 
`customer` must be in `field_ids`, or it is read as null from the base file and 
hides `name`. `address` is in `field_ids` because it is directly nested in 
`customer`, which changed from null to non-null. Its fields are not, because 
`address` is null after the update. |
+| `address` is `{street: '1 Elm', city: 'Austin'}` | `SET address = null` | 
`column_file_1` with `field_ids = [4]` | | `street` and `city` are not in 
`field_ids` because `address` is null after the update. |
+| `address` is null in `column_file_1` with `field_ids = [4]` | `SET street = 
'2 Oak'` | `column_file_2` with `field_ids = [4, 5, 6]`, and `city` null | 
`column_file_2` with `field_ids = [4, 5]` | `city` must be in `field_ids`, or 
it is read as `'Austin'` from the base file. `column_file_1` has no fields left 
and is removed. |

Review Comment:
   With the new strategy discussed here an in slack, updating one field only 
needs that field's ID. The writer reads the struct's null state, one column, to 
keep it matching, so a stats update doesn't need all of content_stats.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.

Review Comment:
   This is removed now. 



##########
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 and must not change unless a column file is 
added to a data file. 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 `file_sequence_number` field represents the sequence number of the 
snapshot that added the file and must also remain unchanged upon assigning at 
commit. The file sequence number can't be used for pruning delete files as the 
data within the file may have an older data sequence number.
 
 When adding a new file to a leaf manifest, its data and file sequence numbers 
are set to `null` because the snapshot's sequence number is not assigned until 
the snapshot is successfully committed. When reading, sequence numbers are 
inherited by replacing `null` with the manifest's sequence number from the 
snapshot root file.
 It is also possible to add a new file with data that logically belongs to an 
older sequence number. In that case, the data sequence number must be provided 
explicitly and not inherited. However, the file sequence number must be always 
assigned when the snapshot is successfully committed.
 
-The data sequence number is inherited only if the entry status is ADDED, or 
MODIFIED by adding a column file. The file sequence number is inherited only if 
the entry status is ADDED. When writing an existing file to a new manifest or 
marking an existing file as deleted, the data and file sequence numbers must be 
non-null and set to the original values that were either inherited or provided 
at the commit time.
+The data sequence number is inherited only if the entry status is ADDED, or 
MODIFIED by adding a column file to a data file. The file sequence number is 
inherited only if the entry status is ADDED. When writing an existing file to a 
new manifest or marking an existing file as deleted, the data and file sequence 
numbers must be non-null and set to the original values that were either 
inherited or provided at the commit time.

Review Comment:
   Makes sense. Applied.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.

Review Comment:
   Sure, I added it here. 



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.

Review Comment:
   Removed. This is covered in the top section now.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).

Review Comment:
   Agreed. I removed the big example and added small examples next to each rule.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.

Review Comment:
   I reworded to say it's about the leaf manifest's own column files, which 
replace fields of its entries. The intent was only that a leaf manifest's 
REPLACED entry can't be written in place the way a data file's can, since the 
root has no manifest DV. That's implied by "in the root manifest", so I removed 
the sentence. I also added that the same commit can change the leaf manifest's 
manifest_info.dv, since replacing DVs while removing entries is the main use 
case.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.
+
+The `tracking` fields of the MODIFIED entry are set as described in [Updating 
Tracking Metadata](#updating-tracking-metadata) and [Sequence Number 
Inheritance](#sequence-number-inheritance), and `tracking.snapshot_id` must be 
the previous entry's (inherited) snapshot ID. The fields of the MODIFIED entry 
outside `tracking` must match the previous entry, except for the following:
+
+- `partition`:
+    - For a data file, an added column file's `field_ids` may have the ID of a 
source field of the data file's partition spec, or of a struct that one is 
nested in, only if all live rows share the same partition values after the 
update. `partition` must be set to those values.
+- `sort_order_id`:
+    - For a data file, if an added column file lists a field in the data 
file's sort order, or a struct that one is nested in, `sort_order_id` must be 
null.

Review Comment:
    Good catch but this rule is gone now and consistency requirement covers it.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.

Review Comment:
   > Tracking changes should be a separate section
   
   Done. Tracking now has its own section, and the data rules moved above it.
   
   > What are you trying to call out?
   
   Added a short line here on what is relevant from that section.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.
+
+The `tracking` fields of the MODIFIED entry are set as described in [Updating 
Tracking Metadata](#updating-tracking-metadata) and [Sequence Number 
Inheritance](#sequence-number-inheritance), and `tracking.snapshot_id` must be 
the previous entry's (inherited) snapshot ID. The fields of the MODIFIED entry 
outside `tracking` must match the previous entry, except for the following:

Review Comment:
   Thanks, I rewrote it to list only what changes, as a `tracking` group.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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

Review Comment:
   It was only in the [tracked file requirements for 
`column_files`](https://github.com/apache/iceberg/blob/ea6870d3ba67fc328ed004e74ee4b11214237c77/format/spec.md?plain=1#L1004).
 I added it here too.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.

Review Comment:
   I moved it into its own paragraph, together with the row alignment rule from 
`Reading` section.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.
+
+The `tracking` fields of the MODIFIED entry are set as described in [Updating 
Tracking Metadata](#updating-tracking-metadata) and [Sequence Number 
Inheritance](#sequence-number-inheritance), and `tracking.snapshot_id` must be 
the previous entry's (inherited) snapshot ID. The fields of the MODIFIED entry 
outside `tracking` must match the previous entry, except for the following:
+
+- `partition`:
+    - For a data file, an added column file's `field_ids` may have the ID of a 
source field of the data file's partition spec, or of a struct that one is 
nested in, only if all live rows share the same partition values after the 
update. `partition` must be set to those values.
+- `sort_order_id`:
+    - For a data file, if an added column file lists a field in the data 
file's sort order, or a struct that one is nested in, `sort_order_id` must be 
null.
+- `content_stats`:
+    - Stats for a field listed in an added column file, and for its nested 
fields, must be recomputed or omitted.
+    - For a leaf manifest, stats that summarize a listed field must be 
recomputed or omitted.
+- `tight_stats`:
+    - If `tight_stats` is true, `content_stats` must be tight for the live 
rows after the update (see [Stats Tightness](#stats-tightness)).
+- `deletion_vector`:
+    - For a data file, every delete that applied to it before the column files 
were added must be written into the MODIFIED entry's `deletion_vector`.
+- `column_files`:
+    - Each field listed in an added column file must be removed from the 
`field_ids` of the previous entry's column files. A column file with no 
remaining `field_ids` must be removed.
+    - For a data file, one of the added column files must have the 
`_last_updated_sequence_number` ID in its `field_ids`, so that rows changed by 
the added column files get a new `_last_updated_sequence_number`. In that 
column file:
+        - If the added column files change the row, 
`_last_updated_sequence_number` must be set to `null` (so that the sequence 
number of the snapshot that added the column files replaces the current value).
+        - If the added column files do not change the row and the row is not 
deleted, `_last_updated_sequence_number` must be copied to the new column file. 
A null value must be replaced with the data sequence number a reader of the 
previous entry would assign.
+
+#### Reading Column Files
+
+Each projected field, including each field nested in a projected field, must 
be read from the column file whose `field_ids` has its ID. A field nested in a 
list or map is read with that list or map. Other projected fields are read from 
the base file, using [Column Projection](#column-projection) for a data file. A 
column file of a data file is also read using [Column 
Projection](#column-projection).

Review Comment:
   Removed. The rules by type are now in the top section.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.
+
+The `tracking` fields of the MODIFIED entry are set as described in [Updating 
Tracking Metadata](#updating-tracking-metadata) and [Sequence Number 
Inheritance](#sequence-number-inheritance), and `tracking.snapshot_id` must be 
the previous entry's (inherited) snapshot ID. The fields of the MODIFIED entry 
outside `tracking` must match the previous entry, except for the following:
+
+- `partition`:
+    - For a data file, an added column file's `field_ids` may have the ID of a 
source field of the data file's partition spec, or of a struct that one is 
nested in, only if all live rows share the same partition values after the 
update. `partition` must be set to those values.
+- `sort_order_id`:
+    - For a data file, if an added column file lists a field in the data 
file's sort order, or a struct that one is nested in, `sort_order_id` must be 
null.
+- `content_stats`:
+    - Stats for a field listed in an added column file, and for its nested 
fields, must be recomputed or omitted.
+    - For a leaf manifest, stats that summarize a listed field must be 
recomputed or omitted.
+- `tight_stats`:
+    - If `tight_stats` is true, `content_stats` must be tight for the live 
rows after the update (see [Stats Tightness](#stats-tightness)).
+- `deletion_vector`:
+    - For a data file, every delete that applied to it before the column files 
were added must be written into the MODIFIED entry's `deletion_vector`.
+- `column_files`:
+    - Each field listed in an added column file must be removed from the 
`field_ids` of the previous entry's column files. A column file with no 
remaining `field_ids` must be removed.
+    - For a data file, one of the added column files must have the 
`_last_updated_sequence_number` ID in its `field_ids`, so that rows changed by 
the added column files get a new `_last_updated_sequence_number`. In that 
column file:
+        - If the added column files change the row, 
`_last_updated_sequence_number` must be set to `null` (so that the sequence 
number of the snapshot that added the column files replaces the current value).
+        - If the added column files do not change the row and the row is not 
deleted, `_last_updated_sequence_number` must be copied to the new column file. 
A null value must be replaced with the data sequence number a reader of the 
previous entry would assign.
+
+#### Reading Column Files
+
+Each projected field, including each field nested in a projected field, must 
be read from the column file whose `field_ids` has its ID. A field nested in a 
list or map is read with that list or map. Other projected fields are read from 
the base file, using [Column Projection](#column-projection) for a data file. A 
column file of a data file is also read using [Column 
Projection](#column-projection).
+
+If a struct is null in a row, every field nested in it is null in that row, 
including a field read from a column file.

Review Comment:
   This is changed now. Every file responsible for part of a struct, including 
the base file, must store the same null state for it in each row. In your 
example, the file with `a` would have to store the struct as non-null too, and 
then a null `a` breaks the not-null constraint, so the row is invalid either 
way.



##########
format/spec.md:
##########
@@ -1801,6 +1805,81 @@ 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
+
+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.
+
+A column file stores the values of the fields whose IDs are in its 
`field_ids`. A list or map is stored as a whole, including every field nested 
in it. For a struct, the column file stores whether the struct is null. Fields 
nested in the struct are stored only if their IDs are also in `field_ids`. A 
column file may also store fields whose IDs are not in its `field_ids`. Readers 
must ignore these fields.
+
+When a column file is added, each ID in its `field_ids` must identify a field 
valid for its base file. For a data file, fields in the current table schema 
and `_last_updated_sequence_number` are valid. For a leaf manifest, fields in 
the `tracked_file` struct are valid. Fields nested in a list or map are not 
valid.
+
+#### 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, and for fields in a null 
struct, should be null. A column file may write a field as optional even if 
that field is required in the table schema.
+
+An added column file must follow these rules for `field_ids`. A field must be 
in `field_ids` if a rule requires it for at least one row where every struct 
that the field is nested in is non-null after the update.
+
+- When a field nested in a list or map changes, the list or map must be in 
`field_ids`.
+- Each non-struct field whose value changes must be in `field_ids`.
+- Each struct that changes between null and non-null must be in `field_ids`.
+- If a struct changes from null to non-null, each field directly nested in it 
must be in `field_ids`, even if the field is null.
+
+See [Column file example](#column-file-example).
+
+When a writer adds column files to a data file, the writer must produce a 
MODIFIED entry and a REPLACED entry. The writer must follow [Updating Tracking 
Metadata](#updating-tracking-metadata) for those entries. The writer may write 
the two entries to different manifests.
+
+When a writer adds column files to a leaf manifest, the writer must produce a 
MODIFIED entry and a REPLACED entry in the root manifest. The REPLACED entry 
must be a full entry in the root manifest. The writer must not replace the 
previous leaf-manifest entry with a manifest deletion vector.
+
+The `tracking` fields of the MODIFIED entry are set as described in [Updating 
Tracking Metadata](#updating-tracking-metadata) and [Sequence Number 
Inheritance](#sequence-number-inheritance), and `tracking.snapshot_id` must be 
the previous entry's (inherited) snapshot ID. The fields of the MODIFIED entry 
outside `tracking` must match the previous entry, except for the following:
+
+- `partition`:
+    - For a data file, an added column file's `field_ids` may have the ID of a 
source field of the data file's partition spec, or of a struct that one is 
nested in, only if all live rows share the same partition values after the 
update. `partition` must be set to those values.
+- `sort_order_id`:
+    - For a data file, if an added column file lists a field in the data 
file's sort order, or a struct that one is nested in, `sort_order_id` must be 
null.
+- `content_stats`:
+    - Stats for a field listed in an added column file, and for its nested 
fields, must be recomputed or omitted.
+    - For a leaf manifest, stats that summarize a listed field must be 
recomputed or omitted.
+- `tight_stats`:
+    - If `tight_stats` is true, `content_stats` must be tight for the live 
rows after the update (see [Stats Tightness](#stats-tightness)).
+- `deletion_vector`:
+    - For a data file, every delete that applied to it before the column files 
were added must be written into the MODIFIED entry's `deletion_vector`.
+- `column_files`:
+    - Each field listed in an added column file must be removed from the 
`field_ids` of the previous entry's column files. A column file with no 
remaining `field_ids` must be removed.
+    - For a data file, one of the added column files must have the 
`_last_updated_sequence_number` ID in its `field_ids`, so that rows changed by 
the added column files get a new `_last_updated_sequence_number`. In that 
column file:
+        - If the added column files change the row, 
`_last_updated_sequence_number` must be set to `null` (so that the sequence 
number of the snapshot that added the column files replaces the current value).
+        - If the added column files do not change the row and the row is not 
deleted, `_last_updated_sequence_number` must be copied to the new column file. 
A null value must be replaced with the data sequence number a reader of the 
previous entry would assign.
+
+#### Reading Column Files
+
+Each projected field, including each field nested in a projected field, must 
be read from the column file whose `field_ids` has its ID. A field nested in a 
list or map is read with that list or map. Other projected fields are read from 
the base file, using [Column Projection](#column-projection) for a data file. A 
column file of a data file is also read using [Column 
Projection](#column-projection).
+
+If a struct is null in a row, every field nested in it is null in that row, 
including a field read from a column file.
+
+A column file and its base file are aligned by row position before the 
attached deletion vector is applied. The scan schema must be used for field 
types and nullability. Null values in a column file may represent deleted rows.
+
+#### Column file example
+
+This example demonstrates which field IDs a column file must have in its 
`field_ids`, using this schema and one row of a data file. Unless a row says 
otherwise, that row in the base file is `customer = {name: …, address: {street: 
'1 Elm', city: 'Austin'}}`. Column files are named `column_file_1`, 
`column_file_2`, and so on. The `_last_updated_sequence_number` ID that each 
update also adds to `field_ids` is left out.
+
+```
+2: optional struct customer {
+  3: optional string name;
+  4: optional struct address {
+    5: optional string street;
+    6: optional string city;
+  }
+}
+8: optional list<string> tags; // element field ID 9
+```
+
+| Row before the update | Update | Valid column files | Invalid column files | 
Notes |

Review Comment:
   Agreed. I removed the big example and added small examples next to each 
rule: primitive fields, a list, and a struct split across two files, including 
the null-state case. They describe valid files, not updates.



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