ShivamSharma43 opened a new pull request, #2630:
URL: https://github.com/apache/iceberg-go/pull/2630
This follows up the review on #2626, which was merged before I could address
it.
In case-insensitive mode, `RenameColumn` could still create two columns
whose names differ only in case. `AddColumn([]string{"x"}, ...)` followed by
`RenameColumn([]string{"age"}, "X")` passed both `Apply` and `Commit`, and the
committed schema had both `X` and `x`. Two renames to `y` and `Y` did the same,
and so did the same thing inside a nested struct.
### Cause
The rename branch of `updateColumn` checked added and renamed columns with
`==`. Only its lookup of existing columns (`findField`) followed the update's
case sensitivity. #2626 fixed this for `AddColumn` with `sameName`, but didn't
touch the rename path.
### Fix
- `AddColumn` and renames now share one check, `nameTaken`. It compares
names with `sameName` and uses the same `parentID`-keyed lookups. The column
being renamed is excluded from the check.
- Two cases that used to be rejected now work. Both follow from the shared
check, and both give a valid schema:
- Renaming a column to its own name with different case in
case-insensitive mode (`name` → `Name`). Before, this failed with `field
already exists: Name`. Java allows it.
- Renaming a column to the name of a column renamed away in the same
update (`name` → `full_name`, then `age` → `name`). `AddColumn` already allowed
this.
- Each operation now has one message for this condition: `cannot add column,
name already exists: %s` (the wording Java uses) and `cannot rename column,
name already exists: %s`. Before, there were five different messages. Both wrap
`iceberg.ErrInvalidSchema`, so callers can match with `errors.Is`. That is the
sentinel already used for an invalid schema, including the `multiple fields for
name` error that `Commit` used to return for these duplicates. I didn't add a
new sentinel.
- The comment now says that Java rejects the renamed-away case and that we
allow it because the resulting schema is valid (the wording suggested in the
review).
### Testing
- New `TestRenameColumnNameAlreadyExists` runs each rejected rename through
both `Apply` and `Commit`. The cases are: an existing column; an existing
column with different case; an added column with different case; another
renamed column with different case; and an added nested column with different
case (`address.town`, then `address.city` → `Town`). The three case-only cases
with added or renamed columns are accepted on main. The test also covers the
two renames that are now allowed. Both are rejected on main.
- `TestAddColumnNameAlreadyExists` has a new nested case: rename
`address.city` to `town`, then add `address.town`. Main already rejected it
(with `field already exists`). The test now also checks `errors.Is(err,
iceberg.ErrInvalidSchema)` and the unified messages.
- Updated the expected messages in
`TestRenameColumn/test_rename_to_existing_name` and
`TestUnionByNameCannotExtendStructAddedByPriorOp`.
- `go vet ./table/` and `golangci-lint run ./table/` (v2.14.0) are clean.
`go test ./table/...` passes, except for the same Windows path-handling
failures as on unmodified main, which are listed in #2626.
This PR was prepared with AI assistance (Claude Code).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]