@@ -106,6 +106,14 @@ Status AppendPartitionSummaries(ArrowArray* array, const ManifestRow& row,
106106 return {};
107107}
108108
109+ Status AppendManifestCount (ArrowArray* array, const std::optional<int32_t >& count,
110+ bool applicable) {
111+ if (!applicable) {
112+ return AppendInt (array, 0 );
113+ }
114+ return count.has_value () ? AppendInt (array, *count) : AppendNull (array);
115+ }
116+
109117Status AppendManifest (ArrowRowBuilder& builder, const ManifestRow& row,
110118 const std::shared_ptr<Schema>& table_schema) {
111119 const auto & manifest = row.manifest ;
@@ -118,17 +126,17 @@ Status AppendManifest(ArrowRowBuilder& builder, const ManifestRow& row,
118126
119127 const bool data = manifest.content == ManifestContent::kData ;
120128 ICEBERG_RETURN_UNEXPECTED (
121- AppendInt (builder.column (5 ), data ? manifest.added_files_count . value_or ( 0 ) : 0 ));
129+ AppendManifestCount (builder.column (5 ), manifest.added_files_count , data ));
122130 ICEBERG_RETURN_UNEXPECTED (
123- AppendInt (builder.column (6 ), data ? manifest.existing_files_count . value_or ( 0 ) : 0 ));
131+ AppendManifestCount (builder.column (6 ), manifest.existing_files_count , data ));
124132 ICEBERG_RETURN_UNEXPECTED (
125- AppendInt (builder.column (7 ), data ? manifest.deleted_files_count . value_or ( 0 ) : 0 ));
133+ AppendManifestCount (builder.column (7 ), manifest.deleted_files_count , data ));
126134 ICEBERG_RETURN_UNEXPECTED (
127- AppendInt (builder.column (8 ), data ? 0 : manifest.added_files_count . value_or ( 0 ) ));
135+ AppendManifestCount (builder.column (8 ), manifest.added_files_count , !data ));
128136 ICEBERG_RETURN_UNEXPECTED (
129- AppendInt (builder.column (9 ), data ? 0 : manifest.existing_files_count . value_or ( 0 ) ));
137+ AppendManifestCount (builder.column (9 ), manifest.existing_files_count , !data ));
130138 ICEBERG_RETURN_UNEXPECTED (
131- AppendInt (builder.column (10 ), data ? 0 : manifest.deleted_files_count . value_or ( 0 ) ));
139+ AppendManifestCount (builder.column (10 ), manifest.deleted_files_count , !data ));
132140
133141 ICEBERG_ASSIGN_OR_RAISE (auto partition_type, row.spec ->PartitionType (*table_schema));
134142 ICEBERG_RETURN_UNEXPECTED (AppendPartitionSummaries (
@@ -150,12 +158,13 @@ const std::shared_ptr<Schema>& ManifestsTable::schema() const {
150158 SchemaField::MakeRequired (2 , " length" , int64 ()),
151159 SchemaField::MakeRequired (3 , " partition_spec_id" , int32 ()),
152160 SchemaField::MakeRequired (4 , " added_snapshot_id" , int64 ()),
153- SchemaField::MakeRequired (5 , " added_data_files_count" , int32 ()),
154- SchemaField::MakeRequired (6 , " existing_data_files_count" , int32 ()),
155- SchemaField::MakeRequired (7 , " deleted_data_files_count" , int32 ()),
156- SchemaField::MakeRequired (15 , " added_delete_files_count" , int32 ()),
157- SchemaField::MakeRequired (16 , " existing_delete_files_count" , int32 ()),
158- SchemaField::MakeRequired (17 , " deleted_delete_files_count" , int32 ()),
161+ // Legacy manifests can omit counts; unknown counts must stay null.
162+ SchemaField::MakeOptional (5 , " added_data_files_count" , int32 ()),
163+ SchemaField::MakeOptional (6 , " existing_data_files_count" , int32 ()),
164+ SchemaField::MakeOptional (7 , " deleted_data_files_count" , int32 ()),
165+ SchemaField::MakeOptional (15 , " added_delete_files_count" , int32 ()),
166+ SchemaField::MakeOptional (16 , " existing_delete_files_count" , int32 ()),
167+ SchemaField::MakeOptional (17 , " deleted_delete_files_count" , int32 ()),
159168 SchemaField::MakeRequired (
160169 8 , " partition_summaries" ,
161170 list (SchemaField::MakeRequired (
0 commit comments