Skip to content

Conversation

@shangxinli
Copy link
Contributor

Implement error vector collection pattern in PendingUpdateTyped to allow builder methods to accumulate validation errors instead of failing fast. This enables users to see all validation issues at once rather than fixing them one by one.

Changes:

  • Add protected error collection methods (AddError, CheckErrors, HasErrors, ClearErrors) to PendingUpdateTyped base class
  • Add std::vector errors_ member to collect validation errors
  • Update PendingUpdate documentation with usage examples
  • Add 6 comprehensive unit tests demonstrating error collection

Pattern follows TableMetadataBuilder implementation.

All tests pass (11/11).

Comment on lines 128 to 130
void AddError(ErrorKind kind, std::string message) {
errors_.emplace_back(kind, std::move(message));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we can add void AddError(Error err) to directly add an existing error without change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

/// Apply() can be used to validate and inspect the uncommitted changes before
/// committing. Commit() applies the changes and commits them to the table.
///
/// Error Collection Pattern:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can make it a separate class so that other builders can leverage this as well? For example, TableMetadataBuilder uses the same pattern: https://github.com/apache/iceberg-cpp/blob/main/src/iceberg/table_metadata.cc#L279

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense

shangxinli added a commit to shangxinli/iceberg-cpp that referenced this pull request Nov 28, 2025
Address review comments from wgtmac on PR apache#358:

1. Add AddError(Error err) overload to accept existing Error objects
   This allows propagating errors from other components without
   deconstructing and reconstructing them.

2. Extract error collection into reusable ErrorCollector utility class
   This eliminates code duplication between PendingUpdateTyped and
   TableMetadataBuilder, and provides a reusable pattern for other
   builders in the codebase.

Changes:
- Add src/iceberg/util/error_collector.h with ErrorCollector class
- Update PendingUpdateTyped to use ErrorCollector internally
- Update TableMetadataBuilder to use ErrorCollector instead of
  std::vector<Error>
- Add test for AddError(Error err) overload
- Add comprehensive documentation with usage examples

All 12 tests pass.
shangxinli added a commit to shangxinli/iceberg-cpp that referenced this pull request Nov 28, 2025
Address review comments from wgtmac on PR apache#358:

1. Add AddError(Error err) overload to accept existing Error objects
   This allows propagating errors from other components without
   deconstructing and reconstructing them.

2. Extract error collection into reusable ErrorCollector utility class
   This eliminates code duplication between PendingUpdateTyped and
   TableMetadataBuilder, and provides a reusable pattern for other
   builders in the codebase.

Changes:
- Add src/iceberg/util/error_collector.h with ErrorCollector class
- Update PendingUpdateTyped to use ErrorCollector internally
- Update TableMetadataBuilder to use ErrorCollector instead of
  std::vector<Error>
- Add test for AddError(Error err) overload
- Add comprehensive documentation with usage examples

All 12 tests pass.
@shangxinli shangxinli force-pushed the error-vector-collection branch from f5c45f3 to ead726d Compare November 28, 2025 14:27
shangxinli and others added 3 commits December 1, 2025 23:01
Implement error vector collection pattern in PendingUpdateTyped
to allow builder methods to accumulate validation errors instead
of failing fast. This enables users to see all validation issues
at once rather than fixing them one by one.

Changes:
- Add protected error collection methods (AddError, CheckErrors,
  HasErrors, ClearErrors) to PendingUpdateTyped base class
- Add std::vector<Error> errors_ member to collect validation errors
- Update PendingUpdate documentation with usage examples
- Add 6 comprehensive unit tests demonstrating error collection

Pattern follows TableMetadataBuilder implementation.

All tests pass (11/11).
Address review comments from wgtmac on PR apache#358:

1. Add AddError(Error err) overload to accept existing Error objects
   This allows propagating errors from other components without
   deconstructing and reconstructing them.

2. Extract error collection into reusable ErrorCollector utility class
   This eliminates code duplication between PendingUpdateTyped and
   TableMetadataBuilder, and provides a reusable pattern for other
   builders in the codebase.

Changes:
- Add src/iceberg/util/error_collector.h with ErrorCollector class
- Update PendingUpdateTyped to use ErrorCollector internally
- Update TableMetadataBuilder to use ErrorCollector instead of
  std::vector<Error>
- Add test for AddError(Error err) overload
- Add comprehensive documentation with usage examples

All 12 tests pass.
@wgtmac wgtmac force-pushed the error-vector-collection branch from ead726d to 7bb446d Compare December 1, 2025 15:33
Copy link
Member

@wgtmac wgtmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shangxinli for working on this! Let's move forward.

@wgtmac wgtmac merged commit b8f5c49 into apache:main Dec 2, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants