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 5cf3cbe68 fix(cli): reject unsupported format versions in upgrade dry
runs (#2460)
5cf3cbe68 is described below
commit 5cf3cbe68f0c6d3ec0866408f8fc41363acf12ad
Author: slfan1989 <[email protected]>
AuthorDate: Tue Nov 10 01:34:42 2026 +0800
fix(cli): reject unsupported format versions in upgrade dry runs (#2460)
Signed-off-by: slfan1989 <[email protected]>
---
cmd/iceberg/upgrade_rollback.go | 26 +++++++++++++-------------
cmd/iceberg/upgrade_rollback_test.go | 16 ++++++++++++++++
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/cmd/iceberg/upgrade_rollback.go b/cmd/iceberg/upgrade_rollback.go
index ecd194e88..6e22e4d8c 100644
--- a/cmd/iceberg/upgrade_rollback.go
+++ b/cmd/iceberg/upgrade_rollback.go
@@ -44,32 +44,32 @@ func runUpgrade(ctx context.Context, output Output, cat
catalog.Catalog, cmd *Up
SpecURL: specURL(cmd.FormatVersion),
}
- if cmd.DryRun {
- output.UpgradeResult(result)
+ if !cmd.DryRun && cmd.FormatVersion <= currentVersion {
+ output.Error(fmt.Errorf("target format version %d must be
greater than current version %d",
+ cmd.FormatVersion, currentVersion))
+ osExit(1)
return
}
- if cmd.FormatVersion <= currentVersion {
- output.Error(fmt.Errorf("target format version %d must be
greater than current version %d",
- cmd.FormatVersion, currentVersion))
+ tx := tbl.NewTransaction()
+ if err := tx.UpgradeFormatVersion(cmd.FormatVersion); err != nil {
+ output.Error(fmt.Errorf("upgrade failed: %w", err))
osExit(1)
return
}
- prompt := fmt.Sprintf("Upgrade %s from format version %d to %d?",
- tableIDString(tbl), currentVersion, cmd.FormatVersion)
- if err := confirmAction(prompt, cmd.Yes); err != nil {
- output.Error(err)
- osExit(1)
+ if cmd.DryRun {
+ output.UpgradeResult(result)
return
}
- tx := tbl.NewTransaction()
- if err := tx.UpgradeFormatVersion(cmd.FormatVersion); err != nil {
- output.Error(fmt.Errorf("upgrade failed: %w", err))
+ prompt := fmt.Sprintf("Upgrade %s from format version %d to %d?",
+ tableIDString(tbl), currentVersion, cmd.FormatVersion)
+ if err := confirmAction(prompt, cmd.Yes); err != nil {
+ output.Error(err)
osExit(1)
return
diff --git a/cmd/iceberg/upgrade_rollback_test.go
b/cmd/iceberg/upgrade_rollback_test.go
index f4a90fcf8..92aff8389 100644
--- a/cmd/iceberg/upgrade_rollback_test.go
+++ b/cmd/iceberg/upgrade_rollback_test.go
@@ -515,6 +515,22 @@ func TestRunUpgradeDryRunAlreadyAtVersion(t *testing.T) {
assert.Contains(t, output, "format version 1 to 1")
}
+func TestRunUpgradeDryRunRejectsUnsupportedVersion(t *testing.T) {
+ cat := &panicCatalog{tbl: upgradeRollbackTestTable(t)}
+ var output errCapture
+
+ exitCode := captureExit(func() {
+ runUpgrade(context.Background(), &output, cat, &UpgradeCmd{
+ TableID: "db.events",
+ FormatVersion: 999,
+ DryRun: true,
+ })
+ })
+
+ assert.Equal(t, 1, exitCode)
+ require.ErrorIs(t, output.lastErr, iceberg.ErrInvalidFormatVersion)
+}
+
func TestConfirmActionNonTTYWithoutYes(t *testing.T) {
err := confirmAction("do something?", false)
require.Error(t, err)