3030#include " iceberg/partition_summary_internal.h"
3131#include " iceberg/result.h"
3232#include " iceberg/schema.h"
33- #include " iceberg/snapshot.h"
3433#include " iceberg/table_metadata.h"
3534#include " iceberg/util/macros.h"
3635
@@ -272,87 +271,41 @@ Result<std::unique_ptr<Writer>> OpenFileWriter(
272271 return writer;
273272}
274273
275- Result<std::unique_ptr<ManifestWriter>> ManifestWriter::MakeV1Writer (
276- std::optional<int64_t > snapshot_id, std::string_view manifest_location,
277- std::shared_ptr<FileIO> file_io, std::shared_ptr<PartitionSpec> partition_spec,
278- std::shared_ptr<Schema> current_schema) {
279- if (manifest_location.empty ()) {
280- return InvalidArgument (" Manifest location cannot be empty" );
281- }
282- if (!file_io) {
283- return InvalidArgument (" FileIO cannot be null" );
284- }
285- if (!partition_spec) {
286- return InvalidArgument (" PartitionSpec cannot be null" );
287- }
288- if (!current_schema) {
289- return InvalidArgument (" Current schema cannot be null" );
290- }
274+ Result<std::unique_ptr<ManifestWriter>> ManifestWriter::MakeWriter (
275+ int8_t format_version, std::optional<int64_t > snapshot_id,
276+ std::string_view manifest_location, std::shared_ptr<FileIO> file_io,
277+ std::shared_ptr<PartitionSpec> partition_spec, std::shared_ptr<Schema> current_schema,
278+ ManifestContent content, std::optional<int64_t > first_row_id) {
279+ ICEBERG_PRECHECK (!manifest_location.empty (), " Manifest location cannot be empty" );
280+ ICEBERG_PRECHECK (file_io, " FileIO cannot be null" );
281+ ICEBERG_PRECHECK (partition_spec, " PartitionSpec cannot be null" );
282+ ICEBERG_PRECHECK (current_schema, " Current schema cannot be null" );
291283
292- auto adapter = std::make_unique<ManifestEntryAdapterV1>(
293- snapshot_id, std::move (partition_spec), std::move (current_schema));
294- ICEBERG_RETURN_UNEXPECTED (adapter->Init ());
295- ICEBERG_RETURN_UNEXPECTED (adapter->StartAppending ());
284+ std::unique_ptr<ManifestEntryAdapter> adapter;
285+ std::optional<int64_t > writer_first_row_id = std::nullopt ;
296286
297- auto schema = adapter->schema ();
298- ICEBERG_ASSIGN_OR_RAISE (
299- auto writer,
300- OpenFileWriter (manifest_location, std::move (schema), std::move (file_io),
301- adapter->metadata (), " manifest_entry" ));
302- return std::unique_ptr<ManifestWriter>(new ManifestWriter (
303- std::move (writer), std::move (adapter), manifest_location, std::nullopt ));
304- }
305-
306- Result<std::unique_ptr<ManifestWriter>> ManifestWriter::MakeV2Writer (
307- std::optional<int64_t > snapshot_id, std::string_view manifest_location,
308- std::shared_ptr<FileIO> file_io, std::shared_ptr<PartitionSpec> partition_spec,
309- std::shared_ptr<Schema> current_schema, ManifestContent content) {
310- if (manifest_location.empty ()) {
311- return InvalidArgument (" Manifest location cannot be empty" );
312- }
313- if (!file_io) {
314- return InvalidArgument (" FileIO cannot be null" );
315- }
316- if (!partition_spec) {
317- return InvalidArgument (" PartitionSpec cannot be null" );
318- }
319- if (!current_schema) {
320- return InvalidArgument (" Current schema cannot be null" );
287+ switch (format_version) {
288+ case 1 : {
289+ adapter = std::make_unique<ManifestEntryAdapterV1>(
290+ snapshot_id, std::move (partition_spec), std::move (current_schema));
291+ break ;
292+ }
293+ case 2 : {
294+ adapter = std::make_unique<ManifestEntryAdapterV2>(
295+ snapshot_id, std::move (partition_spec), std::move (current_schema), content);
296+ break ;
297+ }
298+ case 3 : {
299+ adapter = std::make_unique<ManifestEntryAdapterV3>(
300+ snapshot_id, first_row_id, std::move (partition_spec), std::move (current_schema),
301+ content);
302+ writer_first_row_id = first_row_id;
303+ break ;
304+ }
305+ default :
306+ return NotSupported (" Format version {} is not supported" , format_version);
321307 }
322- auto adapter = std::make_unique<ManifestEntryAdapterV2>(
323- snapshot_id, std::move (partition_spec), std::move (current_schema), content);
324- ICEBERG_RETURN_UNEXPECTED (adapter->Init ());
325- ICEBERG_RETURN_UNEXPECTED (adapter->StartAppending ());
326-
327- auto schema = adapter->schema ();
328- ICEBERG_ASSIGN_OR_RAISE (
329- auto writer,
330- OpenFileWriter (manifest_location, std::move (schema), std::move (file_io),
331- adapter->metadata (), " manifest_entry" ));
332- return std::unique_ptr<ManifestWriter>(new ManifestWriter (
333- std::move (writer), std::move (adapter), manifest_location, std::nullopt ));
334- }
335308
336- Result<std::unique_ptr<ManifestWriter>> ManifestWriter::MakeV3Writer (
337- std::optional<int64_t > snapshot_id, std::optional<int64_t > first_row_id,
338- std::string_view manifest_location, std::shared_ptr<FileIO> file_io,
339- std::shared_ptr<PartitionSpec> partition_spec, std::shared_ptr<Schema> current_schema,
340- ManifestContent content) {
341- if (manifest_location.empty ()) {
342- return InvalidArgument (" Manifest location cannot be empty" );
343- }
344- if (!file_io) {
345- return InvalidArgument (" FileIO cannot be null" );
346- }
347- if (!partition_spec) {
348- return InvalidArgument (" PartitionSpec cannot be null" );
349- }
350- if (!current_schema) {
351- return InvalidArgument (" Current schema cannot be null" );
352- }
353- auto adapter = std::make_unique<ManifestEntryAdapterV3>(
354- snapshot_id, first_row_id, std::move (partition_spec), std::move (current_schema),
355- content);
356309 ICEBERG_RETURN_UNEXPECTED (adapter->Init ());
357310 ICEBERG_RETURN_UNEXPECTED (adapter->StartAppending ());
358311
@@ -362,28 +315,7 @@ Result<std::unique_ptr<ManifestWriter>> ManifestWriter::MakeV3Writer(
362315 OpenFileWriter (manifest_location, std::move (schema), std::move (file_io),
363316 adapter->metadata (), " manifest_entry" ));
364317 return std::unique_ptr<ManifestWriter>(new ManifestWriter (
365- std::move (writer), std::move (adapter), manifest_location, first_row_id));
366- }
367-
368- Result<std::unique_ptr<ManifestWriter>> ManifestWriter::MakeWriter (
369- int8_t format_version, std::optional<int64_t > snapshot_id,
370- std::string_view manifest_location, std::shared_ptr<FileIO> file_io,
371- std::shared_ptr<PartitionSpec> partition_spec, std::shared_ptr<Schema> current_schema,
372- ManifestContent content, std::optional<int64_t > first_row_id) {
373- switch (format_version) {
374- case 1 :
375- return MakeV1Writer (snapshot_id, manifest_location, std::move (file_io),
376- std::move (partition_spec), std::move (current_schema));
377- case 2 :
378- return MakeV2Writer (snapshot_id, manifest_location, std::move (file_io),
379- std::move (partition_spec), std::move (current_schema), content);
380- case 3 :
381- return MakeV3Writer (snapshot_id, first_row_id, manifest_location,
382- std::move (file_io), std::move (partition_spec),
383- std::move (current_schema), content);
384- default :
385- return NotSupported (" Format version {} is not supported" , format_version);
386- }
318+ std::move (writer), std::move (adapter), manifest_location, writer_first_row_id));
387319}
388320
389321ManifestListWriter::ManifestListWriter (std::unique_ptr<Writer> writer,
@@ -420,83 +352,47 @@ std::optional<int64_t> ManifestListWriter::next_row_id() const {
420352 return adapter_->next_row_id ();
421353}
422354
423- Result<std::unique_ptr<ManifestListWriter>> ManifestListWriter::MakeV1Writer (
424- int64_t snapshot_id, std::optional<int64_t > parent_snapshot_id,
425- std::string_view manifest_list_location, std::shared_ptr<FileIO> file_io) {
426- auto adapter = std::make_unique<ManifestFileAdapterV1>(snapshot_id, parent_snapshot_id);
427- ICEBERG_RETURN_UNEXPECTED (adapter->Init ());
428- ICEBERG_RETURN_UNEXPECTED (adapter->StartAppending ());
429-
430- auto schema = adapter->schema ();
431- ICEBERG_ASSIGN_OR_RAISE (
432- auto writer,
433- OpenFileWriter (manifest_list_location, std::move (schema), std::move (file_io),
434- adapter->metadata (), " manifest_file" ));
435- return std::unique_ptr<ManifestListWriter>(
436- new ManifestListWriter (std::move (writer), std::move (adapter)));
437- }
438-
439- Result<std::unique_ptr<ManifestListWriter>> ManifestListWriter::MakeV2Writer (
440- int64_t snapshot_id, std::optional<int64_t > parent_snapshot_id,
441- int64_t sequence_number, std::string_view manifest_list_location,
442- std::shared_ptr<FileIO> file_io) {
443- auto adapter = std::make_unique<ManifestFileAdapterV2>(snapshot_id, parent_snapshot_id,
444- sequence_number);
445- ICEBERG_RETURN_UNEXPECTED (adapter->Init ());
446- ICEBERG_RETURN_UNEXPECTED (adapter->StartAppending ());
447-
448- auto schema = adapter->schema ();
449- ICEBERG_ASSIGN_OR_RAISE (
450- auto writer,
451- OpenFileWriter (manifest_list_location, std::move (schema), std::move (file_io),
452- adapter->metadata (), " manifest_file" ));
453-
454- return std::unique_ptr<ManifestListWriter>(
455- new ManifestListWriter (std::move (writer), std::move (adapter)));
456- }
457-
458- Result<std::unique_ptr<ManifestListWriter>> ManifestListWriter::MakeV3Writer (
459- int64_t snapshot_id, std::optional<int64_t > parent_snapshot_id,
460- int64_t sequence_number, int64_t first_row_id,
461- std::string_view manifest_list_location, std::shared_ptr<FileIO> file_io) {
462- auto adapter = std::make_unique<ManifestFileAdapterV3>(snapshot_id, parent_snapshot_id,
463- sequence_number, first_row_id);
464- ICEBERG_RETURN_UNEXPECTED (adapter->Init ());
465- ICEBERG_RETURN_UNEXPECTED (adapter->StartAppending ());
466-
467- auto schema = adapter->schema ();
468- ICEBERG_ASSIGN_OR_RAISE (
469- auto writer,
470- OpenFileWriter (manifest_list_location, std::move (schema), std::move (file_io),
471- adapter->metadata (), " manifest_file" ));
472- return std::unique_ptr<ManifestListWriter>(
473- new ManifestListWriter (std::move (writer), std::move (adapter)));
474- }
475-
476355Result<std::unique_ptr<ManifestListWriter>> ManifestListWriter::MakeWriter (
477356 int8_t format_version, int64_t snapshot_id, std::optional<int64_t > parent_snapshot_id,
478357 std::string_view manifest_list_location, std::shared_ptr<FileIO> file_io,
479358 std::optional<int64_t > sequence_number, std::optional<int64_t > first_row_id) {
359+ std::unique_ptr<ManifestFileAdapter> adapter;
360+
480361 switch (format_version) {
481- case 1 :
482- return MakeV1Writer (snapshot_id, parent_snapshot_id, manifest_list_location,
483- std::move (file_io));
484- case 2 :
362+ case 1 : {
363+ adapter = std::make_unique<ManifestFileAdapterV1>(snapshot_id, parent_snapshot_id);
364+ break ;
365+ }
366+ case 2 : {
485367 ICEBERG_PRECHECK (sequence_number.has_value (),
486368 " Sequence number is required for format version 2" );
487- return MakeV2Writer (snapshot_id, parent_snapshot_id, sequence_number.value (),
488- manifest_list_location, std::move (file_io));
489- case 3 :
369+ adapter = std::make_unique<ManifestFileAdapterV2>(snapshot_id, parent_snapshot_id,
370+ sequence_number.value ());
371+ break ;
372+ }
373+ case 3 : {
490374 ICEBERG_PRECHECK (sequence_number.has_value (),
491375 " Sequence number is required for format version 3" );
492376 ICEBERG_PRECHECK (first_row_id.has_value (),
493377 " First row ID is required for format version 3" );
494- return MakeV3Writer (snapshot_id, parent_snapshot_id, sequence_number.value (),
495- first_row_id.value (), manifest_list_location,
496- std::move (file_io));
378+ adapter = std::make_unique<ManifestFileAdapterV3>(
379+ snapshot_id, parent_snapshot_id, sequence_number.value (), first_row_id.value ());
380+ break ;
381+ }
497382 default :
498383 return NotSupported (" Format version {} is not supported" , format_version);
499384 }
385+
386+ ICEBERG_RETURN_UNEXPECTED (adapter->Init ());
387+ ICEBERG_RETURN_UNEXPECTED (adapter->StartAppending ());
388+
389+ auto schema = adapter->schema ();
390+ ICEBERG_ASSIGN_OR_RAISE (
391+ auto writer,
392+ OpenFileWriter (manifest_list_location, std::move (schema), std::move (file_io),
393+ adapter->metadata (), " manifest_file" ));
394+ return std::unique_ptr<ManifestListWriter>(
395+ new ManifestListWriter (std::move (writer), std::move (adapter)));
500396}
501397
502398} // namespace iceberg
0 commit comments