xndai commented on code in PR #1070:
URL: https://github.com/apache/iceberg-cpp/pull/1070#discussion_r4724740390
##########
src/iceberg/inspect/snapshots_table.cc:
##########
@@ -83,13 +83,19 @@ constexpr
std::array<internal::MetadataTableColumn<Snapshot>, 6> kSnapshotColumn
return row.manifest_list.empty() ? AppendNull(column)
: AppendString(column,
row.manifest_list);
}},
- {.field_id = 6, .append = [](ArrowArray* column, const Snapshot& row) {
- if (row.summary.empty()) {
- return AppendNull(column);
- }
- auto summary = row.summary;
- summary.erase(SnapshotSummaryFields::kOperation);
- return AppendStringMap(column, summary);
+ {.field_id = 6,
+ .append =
+ [](ArrowArray* column, const Snapshot& row) {
+ if (row.summary.empty()) {
+ return AppendNull(column);
+ }
+ auto summary = row.summary;
+ summary.erase(SnapshotSummaryFields::kOperation);
+ return AppendStringMap(column, summary);
+ }},
+ {.field_id = 9, .append = [](ArrowArray* column, const Snapshot& row) {
Review Comment:
Why is this field_id 9 instead of 7?
##########
src/iceberg/json_serde.cc:
##########
@@ -1130,7 +1135,19 @@ Result<std::unique_ptr<Snapshot>> SnapshotFromJson(const
nlohmann::json& json) {
ICEBERG_ASSIGN_OR_RAISE(auto unix_ms, GetJsonValue<int64_t>(json,
kTimestampMs));
auto timestamp_ms = TimePointMsFromUnixMs(unix_ms);
ICEBERG_ASSIGN_OR_RAISE(auto manifest_list,
- GetJsonValue<std::string>(json, kManifestList));
+ GetJsonValueOptional<std::string>(json,
kManifestList));
+ ICEBERG_ASSIGN_OR_RAISE(auto root_manifest,
+ GetJsonValueOptional<std::string>(json,
kRootManifest));
+ if (manifest_list.has_value() == root_manifest.has_value()) {
Review Comment:
rewrite it into two error condition -
if (..has_value() && .. has_value()) and
if (!has_value() && !has_value())
and report separate errors. This way it's much easier to trouble shoot
malformed json file.
##########
src/iceberg/json_serde.cc:
##########
@@ -1130,7 +1135,19 @@ Result<std::unique_ptr<Snapshot>> SnapshotFromJson(const
nlohmann::json& json) {
ICEBERG_ASSIGN_OR_RAISE(auto unix_ms, GetJsonValue<int64_t>(json,
kTimestampMs));
auto timestamp_ms = TimePointMsFromUnixMs(unix_ms);
ICEBERG_ASSIGN_OR_RAISE(auto manifest_list,
- GetJsonValue<std::string>(json, kManifestList));
+ GetJsonValueOptional<std::string>(json,
kManifestList));
+ ICEBERG_ASSIGN_OR_RAISE(auto root_manifest,
Review Comment:
should we only try to parse root_manifest when version is 4?
##########
src/iceberg/table_metadata.cc:
##########
@@ -790,6 +843,19 @@ Status
TableMetadataBuilder::Impl::UpgradeFormatVersion(int8_t new_format_versio
return {};
}
+ // A create transaction may upgrade before selecting the current schema.
+ // Build() checks identifier-field compatibility across all schemas.
Review Comment:
> Build() checks identifier-field compatibility across all schemas.
but why the check below only checks against current schema? is it still
going to fail at Build()?
##########
src/iceberg/catalog/rest/rest_catalog.cc:
##########
@@ -856,6 +856,16 @@ Result<CommitTableResponse>
RestCatalog::UpdateTableInternal(
const std::vector<std::unique_ptr<TableUpdate>>& updates,
auth::AuthSession& session) {
ICEBERG_ENDPOINT_CHECK(supported_endpoints_, Endpoint::UpdateTable());
+ // The server may have roots absent from the client, including after an
upgrade.
Review Comment:
Looks like you are going to fail all versions including v1 to v3.
##########
src/iceberg/snapshot.cc:
##########
@@ -165,6 +166,36 @@ Result<std::optional<int64_t>> Snapshot::FirstRowId()
const { return first_row_i
Result<std::optional<int64_t>> Snapshot::AddedRows() const { return
added_rows; }
+Status Snapshot::ValidateForFormatVersion(int8_t format_version,
+ bool is_new_snapshot) const {
+ if (is_new_snapshot && format_version >=
TableMetadata::kMinFormatVersionRootManifest) {
+ ICEBERG_CHECK(root_manifest.has_value(),
+ "New v{} snapshots require root-manifest instead of
manifest-list",
+ format_version);
+ }
+ if (root_manifest.has_value()) {
+ ICEBERG_CHECK(format_version >=
TableMetadata::kMinFormatVersionRootManifest,
+ "root-manifest requires format version {}",
+ TableMetadata::kMinFormatVersionRootManifest);
+ ICEBERG_CHECK(manifest_list.empty(),
Review Comment:
Can we wrap these checks into a version awared validate function similar to
#1169 ?
##########
src/iceberg/catalog/rest/rest_catalog.cc:
##########
@@ -856,6 +856,16 @@ Result<CommitTableResponse>
RestCatalog::UpdateTableInternal(
const std::vector<std::unique_ptr<TableUpdate>>& updates,
auth::AuthSession& session) {
ICEBERG_ENDPOINT_CHECK(supported_endpoints_, Endpoint::UpdateTable());
+ // The server may have roots absent from the client, including after an
upgrade.
Review Comment:
What is this block of code? How does this relate to v4 support?
##########
src/iceberg/table_metadata.cc:
##########
@@ -320,6 +321,58 @@ Result<std::shared_ptr<Snapshot>>
TableMetadata::SnapshotById(int64_t snapshot_i
return *iter;
}
+bool TableMetadata::HasRootManifest() const {
+ return std::ranges::any_of(snapshots, [](const auto& snapshot) {
+ return snapshot && snapshot->root_manifest.has_value();
+ });
+}
+
+Status TableMetadata::ValidateLocation() const {
Review Comment:
All these location validation need to account for relative path. Refer to
#1124. Ok to resolve as a follow up but pls log an issue.
##########
src/iceberg/snapshot.cc:
##########
@@ -165,6 +166,36 @@ Result<std::optional<int64_t>> Snapshot::FirstRowId()
const { return first_row_i
Result<std::optional<int64_t>> Snapshot::AddedRows() const { return
added_rows; }
+Status Snapshot::ValidateForFormatVersion(int8_t format_version,
+ bool is_new_snapshot) const {
+ if (is_new_snapshot && format_version >=
TableMetadata::kMinFormatVersionRootManifest) {
+ ICEBERG_CHECK(root_manifest.has_value(),
Review Comment:
and check the manifest list doesn't set?
##########
src/iceberg/table_metadata.cc:
##########
@@ -320,6 +321,58 @@ Result<std::shared_ptr<Snapshot>>
TableMetadata::SnapshotById(int64_t snapshot_i
return *iter;
}
+bool TableMetadata::HasRootManifest() const {
+ return std::ranges::any_of(snapshots, [](const auto& snapshot) {
+ return snapshot && snapshot->root_manifest.has_value();
+ });
+}
+
+Status TableMetadata::ValidateLocation() const {
+ if (format_version >= kMinFormatVersionOptionalLocation) {
+ if (location.empty()) {
+ return NotSupported("V{} tables without a location are not supported
yet",
+ format_version);
+ }
+ ICEBERG_PRECHECK(!LocationUtil::ParseScheme(location).empty(),
+ "V{} table location must be absolute: {}",
format_version, location);
+ }
+ return {};
+}
+
+Status TableMetadata::ValidateIdentifierFields() const {
+ if (format_version >= kMinFormatVersionConstraints &&
+ std::ranges::any_of(schemas, [](const auto& schema) {
Review Comment:
You check all schemas here instead of just current schema. This is
inconsistent with `UpgradeFormatVersion`. So the upgrade could succeed but then
Build() would fail. Need to fix this.
##########
src/iceberg/table_metadata.cc:
##########
@@ -790,6 +843,19 @@ Status
TableMetadataBuilder::Impl::UpgradeFormatVersion(int8_t new_format_versio
return {};
}
+ // A create transaction may upgrade before selecting the current schema.
+ // Build() checks identifier-field compatibility across all schemas.
+ if (new_format_version >= TableMetadata::kMinFormatVersionConstraints) {
+ auto current_schema = schemas_by_id_.find(metadata_.current_schema_id);
+ if (current_schema != schemas_by_id_.end() &&
+ !current_schema->second->IdentifierFieldIds().empty()) {
+ return NotSupported(
+ "Cannot upgrade a table with identifier fields to format version {}:
"
Review Comment:
Can you add a link to v4 proposal/spec regarding this limitation? I am not
aware and am curious why.
--
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]