Skip to content

feat(#492): implement SetStatistics, RemoveStatistics, AddEncryptionKey, RemoveEncryptionKey updates#902

Merged
zeroshade merged 4 commits into
apache:mainfrom
tanmayrauth:feat/missing-table-updates-492
Apr 16, 2026
Merged

feat(#492): implement SetStatistics, RemoveStatistics, AddEncryptionKey, RemoveEncryptionKey updates#902
zeroshade merged 4 commits into
apache:mainfrom
tanmayrauth:feat/missing-table-updates-492

Conversation

@tanmayrauth
Copy link
Copy Markdown
Contributor

Adds the four remaining table update types required for REST catalog compatibility. Without these, any commit response containing these actions fails with "unknown update action".

Changes:

  • table/encryption.go: new file; defines EncryptionKey type (key-id, key-metadata, key-algorithm) separate from statistics types
  • table/statistics.go: remove EncryptionKey (moved to encryption.go)
  • table/updates.go: add constants and update structs for set-statistics, remove-statistics, add-encryption-key, remove-encryption-key; register all four in UnmarshalJSON
  • table/metadata.go:
    • add EncryptionKeys() iter.Seq2[string, EncryptionKey] to Metadata interface and implement on commonMetadata
    • add EncryptionKeyMap field to commonMetadata with JSON tag encryption-keys (omitempty; inert on V1/V2 tables)
    • add encryptionKeyMap to MetadataBuilder; initialize in NewMetadataBuilder alongside refs; copy in MetadataBuilderFromBase; write through in buildCommonMetadata
    • add SetStatistics (upsert by snapshot-id), RemoveStatistics, AddEncryptionKey, RemoveEncryptionKey builder methods
    • include EncryptionKeyMap in commonMetadata.Equals
  • table/updates_test.go: unmarshal and Apply tests for all four update types including replace-not-append semantics for SetStatistics and no-op remove cases

Feature #492

@tanmayrauth tanmayrauth requested a review from zeroshade as a code owner April 15, 2026 04:07
@tanmayrauth tanmayrauth mentioned this pull request Apr 15, 2026
2 tasks
@tanmayrauth
Copy link
Copy Markdown
Contributor Author

@zeroshade Can you please review this change and merge if the changes are okay?

Comment thread table/encryption.go
Comment on lines +22 to 26
type EncryptionKey struct {
KeyID string `json:"key-id"`
KeyMetadata *string `json:"key-metadata,omitempty"`
KeyAlgorithm *string `json:"key-algorithm,omitempty"`
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These aren't the correct json keys according to the spec, for example it should be encrypted-key-metadata not key-metadata, there is no KeyAlgorithm in the spec and you're missing the "Properties" member. Please update to follow the v3 spec

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Renamed to encrypted-key-metadata, removed key-algorithm, added properties field per the V3 spec.

Comment thread table/metadata.go Outdated
SnapshotRefs map[string]SnapshotRef `json:"refs,omitempty"`
StatisticsList []StatisticsFile `json:"statistics,omitempty"`
PartitionStatsList []PartitionStatisticsFile `json:"partition-statistics,omitempty"`
EncryptionKeyMap map[string]EncryptionKey `json:"encryption-keys,omitempty"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

According to the spec, encryption-keys is a list, not a map

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, I've changed from map[string]EncryptionKey to []EncryptionKey throughout metadata, builder, and interface.

Copy link
Copy Markdown
Contributor

@laskoviymishka laskoviymishka left a comment

Choose a reason for hiding this comment

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

maps.Equal on EncryptionKey is broken — *string fields compared by pointer address, not value. V3 gating missing for encryption keys.

Comment thread table/metadata.go Outdated
slices.Equal(c.SnapshotLog, other.SnapshotLog) && slices.Equal(c.MetadataLog, other.MetadataLog) &&
iceinternal.SliceEqualHelper(c.SortOrderList, other.SortOrderList)
iceinternal.SliceEqualHelper(c.SortOrderList, other.SortOrderList) &&
maps.Equal(c.EncryptionKeyMap, other.EncryptionKeyMap)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think this is a bug

EncryptionKey has *string fields (KeyMetadata, KeyAlgorithm). maps.Equal uses == — compares pointer addresses, not values. Two keys deserialized from the same JSON will have different pointers. Equals() returns false for identical metadata. Use maps.EqualFunc with reflect.DeepEqual like SnapshotRefs three lines above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now using iceinternal.SliceEqualHelper with an Equals() method on EncryptionKey that does proper value comparison of *string fields and map[string]string properties.

Comment thread table/metadata.go
}

// AddEncryptionKey adds or replaces an encryption key indexed by its key-id.
func (b *MetadataBuilder) AddEncryptionKey(key EncryptionKey) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Encryption keys are V3+. No format version check. The codebase already gates V3 features — see minFormatVersionRowLineage. Add a b.formatVersion < 3 guard.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. AddEncryptionKey now rejects calls when formatVersion < 3 with a descriptive error, consistent with the existing minFormatVersionRowLineage pattern.

…Key, RemoveEncryptionKey updates

Adds the four remaining table update types required for REST catalog
compatibility. Without these, any commit response containing these
actions fails with "unknown update action".

Changes:
- table/encryption.go: new file; defines EncryptionKey type (key-id,
  key-metadata, key-algorithm) separate from statistics types
- table/statistics.go: remove EncryptionKey (moved to encryption.go)
- table/updates.go: add constants and update structs for
  set-statistics, remove-statistics, add-encryption-key,
  remove-encryption-key; register all four in UnmarshalJSON
- table/metadata.go:
  - add EncryptionKeys() iter.Seq2[string, EncryptionKey] to Metadata
    interface and implement on commonMetadata
  - add EncryptionKeyMap field to commonMetadata with JSON tag
    encryption-keys (omitempty; inert on V1/V2 tables)
  - add encryptionKeyMap to MetadataBuilder; initialize in
    NewMetadataBuilder alongside refs; copy in MetadataBuilderFromBase;
    write through in buildCommonMetadata
  - add SetStatistics (upsert by snapshot-id), RemoveStatistics,
    AddEncryptionKey, RemoveEncryptionKey builder methods
  - include EncryptionKeyMap in commonMetadata.Equals
- table/updates_test.go: unmarshal and Apply tests for all four
  update types including replace-not-append semantics for
  SetStatistics and no-op remove cases
- Fix EncryptionKey struct: rename key-metadata to encrypted-key-metadata,
  remove key-algorithm, add encrypted-by-id and properties fields
- Change encryption-keys from map to list per spec
- Fix equality check using Equals method instead of maps.Equal
- Add V3 format version guard to AddEncryptionKey
@tanmayrauth tanmayrauth force-pushed the feat/missing-table-updates-492 branch from a9efcfd to 98adfba Compare April 16, 2026 04:13
Copy link
Copy Markdown
Contributor

@laskoviymishka laskoviymishka left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Copy Markdown
Member

@zeroshade zeroshade left a comment

Choose a reason for hiding this comment

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

Just one nitpick and then we're good

Comment thread table/encryption.go Outdated
@zeroshade zeroshade merged commit c5f82b5 into apache:main Apr 16, 2026
14 checks passed
zeroshade pushed a commit that referenced this pull request May 6, 2026
…isticsUpdate (#1018)

Adds SetPartitionStatisticsUpdate and RemovePartitionStatisticsUpdate in
table/updates.go with MetadataBuilder methods and UnmarshalJSON wiring.
Mirrors the existing SetStatisticsUpdate / RemoveStatisticsUpdate from
#902.

Closes #1009
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.

3 participants