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 2a3456f feat(table): add Refresh method to reload table metadata
(#520)
2a3456f is described below
commit 2a3456fce0d86f08fd30d769c3229be5152a9e98
Author: Blue Li <[email protected]>
AuthorDate: Thu Aug 7 00:12:19 2025 +0800
feat(table): add Refresh method to reload table metadata (#520)
## Description
Add `Refresh` method to `Table` struct for reloading table metadata.
## Changes
- Add `Refresh` method in `table/table.go`
- Add corresponding test cases in `table/table_test.go`
## Use Case
When table metadata changes (e.g., modified by other processes), you can
call `Refresh` to get the latest table state.
---
table/table.go | 13 +++++++++++++
table/table_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
diff --git a/table/table.go b/table/table.go
index b49b240..0bd3ba3 100644
--- a/table/table.go
+++ b/table/table.go
@@ -92,6 +92,19 @@ func (t Table) NewTransaction() *Transaction {
}
}
+func (t *Table) Refresh(ctx context.Context) error {
+ fresh, err := t.cat.LoadTable(ctx, t.identifier, nil)
+ if err != nil {
+ return err
+ }
+
+ t.metadata = fresh.metadata
+ t.fsF = fresh.fsF
+ t.metadataLocation = fresh.metadataLocation
+
+ return nil
+}
+
// AppendTable is a shortcut for NewTransaction().AppendTable() and then
committing the transaction
func (t Table) AppendTable(ctx context.Context, tbl arrow.Table, batchSize
int64, snapshotProps iceberg.Properties) (*Table, error) {
txn := t.NewTransaction()
diff --git a/table/table_test.go b/table/table_test.go
index ff4ec03..11322c2 100644
--- a/table/table_test.go
+++ b/table/table_test.go
@@ -1473,3 +1473,48 @@ func (t *TableWritingTestSuite)
TestDeleteOldMetadataNoErrorLogsOnFileFound() {
t.NotContains(logOutput, "Warning: Failed to delete old metadata file")
t.NotContains(logOutput, "no such file or directory")
}
+
+func (t *TableTestSuite) TestRefresh() {
+ cat, err := catalog.Load(context.Background(), "default",
iceberg.Properties{
+ "uri": ":memory:",
+ "type": "sql",
+ sql.DriverKey: sqliteshim.ShimName,
+ sql.DialectKey: string(sql.SQLite),
+ "warehouse": "file://" + t.T().TempDir(),
+ })
+ t.Require().NoError(err)
+
+ ident := table.Identifier{"test", "refresh_table"}
+ t.Require().NoError(cat.CreateNamespace(context.Background(),
catalog.NamespaceFromIdent(ident), nil))
+
+ tbl, err := cat.CreateTable(context.Background(), ident, t.tbl.Schema(),
+ catalog.WithProperties(iceberg.Properties{"original": "true"}))
+ t.Require().NoError(err)
+ t.Require().NotNil(tbl)
+
+ originalProperties := tbl.Properties()
+ originalIdentifier := tbl.Identifier()
+ originalLocation := tbl.Location()
+ originalSchema := tbl.Schema()
+ originalSpec := tbl.Spec()
+
+ _, _, err = cat.CommitTable(context.Background(), tbl, nil,
[]table.Update{
+ table.NewSetPropertiesUpdate(iceberg.Properties{
+ "refreshed": "true",
+ "timestamp": strconv.FormatInt(time.Now().Unix(), 10),
+ }),
+ })
+ t.Require().NoError(err)
+
+ err = tbl.Refresh(context.Background())
+ t.Require().NoError(err)
+ t.Require().NotNil(tbl)
+
+ t.Equal("true", tbl.Properties()["refreshed"])
+ t.NotEqual(originalProperties, tbl.Properties())
+
+ t.Equal(originalIdentifier, tbl.Identifier())
+ t.Equal(originalLocation, tbl.Location())
+ t.True(originalSchema.Equals(tbl.Schema()))
+ t.Equal(originalSpec, tbl.Spec())
+}