You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by ze...@apache.org on 2026/04/14 21:00:24 UTC
(iceberg-go) branch main updated: feat(table): support committing snapshots to branches other than main (#899)
This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new aa6f01d7 feat(table): support committing snapshots to branches other than main (#899)
aa6f01d7 is described below
commit aa6f01d768087fc85a6d2ea4b754042421204bf4
Author: Ali Asghar <98...@users.noreply.github.com>
AuthorDate: Wed Apr 15 02:00:17 2026 +0500
feat(table): support committing snapshots to branches other than main (#899)
Fixes #714.
Adds `Table.NewTransactionOnBranch(branch string)` so callers can commit
to a named branch. The existing `NewTransaction()` becomes a convenience
wrapper for `NewTransactionOnBranch(MainBranch)`.
The branch name flows through `Transaction.branch` into
`snapshotProducer`, replacing the two hardcoded `"main"` strings in
`NewSetSnapshotRefUpdate` and `AssertRefSnapshotID`.
```go
// Commit to a feature branch
txn := tbl.NewTransactionOnBranch("my-feature-branch")
if err := txn.Append(ctx, reader, nil); err != nil { ... }
if _, err := txn.Commit(ctx); err != nil { ... }
```
Signed-off-by: alliasgher <al...@gmail.com>
---
table/snapshot_producers.go | 9 +++++++--
table/table.go | 13 ++++++++++---
table/transaction.go | 5 +++--
3 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/table/snapshot_producers.go b/table/snapshot_producers.go
index 59a1775f..ffeda737 100644
--- a/table/snapshot_producers.go
+++ b/table/snapshot_producers.go
@@ -814,10 +814,15 @@ func (sp *snapshotProducer) commit(ctx context.Context) (_ []Update, _ []Require
snapshot.AddedRows = &addedRows
}
+ branch := sp.txn.branch
+ if branch == "" {
+ branch = MainBranch
+ }
+
return []Update{
NewAddSnapshotUpdate(&snapshot),
- NewSetSnapshotRefUpdate("main", sp.snapshotID, BranchRef, -1, -1, -1),
+ NewSetSnapshotRefUpdate(branch, sp.snapshotID, BranchRef, -1, -1, -1),
}, []Requirement{
- AssertRefSnapshotID("main", sp.txn.meta.currentSnapshotID),
+ AssertRefSnapshotID(branch, sp.txn.meta.currentSnapshotID),
}, nil
}
diff --git a/table/table.go b/table/table.go
index 084b37ff..0338db6b 100644
--- a/table/table.go
+++ b/table/table.go
@@ -87,12 +87,19 @@ func (t Table) LocationProvider() (LocationProvider, error) {
}
func (t Table) NewTransaction() *Transaction {
+ return t.NewTransactionOnBranch(MainBranch)
+}
+
+// NewTransactionOnBranch creates a new transaction that commits to the named
+// branch. Use [NewTransaction] to commit to the default "main" branch.
+func (t Table) NewTransactionOnBranch(branch string) *Transaction {
meta, _ := MetadataBuilderFromBase(t.metadata, t.metadataLocation)
return &Transaction{
- tbl: &t,
- meta: meta,
- reqs: []Requirement{},
+ tbl: &t,
+ meta: meta,
+ branch: branch,
+ reqs: []Requirement{},
}
}
diff --git a/table/transaction.go b/table/transaction.go
index 6e635851..23da204d 100644
--- a/table/transaction.go
+++ b/table/transaction.go
@@ -64,8 +64,9 @@ func (s snapshotUpdate) mergeAppend() *snapshotProducer {
}
type Transaction struct {
- tbl *Table
- meta *MetadataBuilder
+ tbl *Table
+ meta *MetadataBuilder
+ branch string
reqs []Requirement