ShivamSharma43 opened a new issue, #2469:
URL: https://github.com/apache/iceberg-go/issues/2469
### Apache Iceberg version
main (development)
### Please describe the bug 🐞
Replacing a view with a definition it already had (for example, reverting to
an earlier query) fails with `duplicate version-id`. The same happens when
applying an `add-view-version` update whose content matches a version already
in the metadata.
Reproduced on main (d840452):
```go
sc := iceberg.NewSchema(0, iceberg.NestedField{ID: 1, Name: "x", Type:
iceberg.PrimitiveTypes.Int64})
version := func(id int64, sql string) *view.Version {
v, _ := view.NewVersionFromSQL(id, 0,
view.Representation{SQL: sql, Dialect: "spark"},
table.Identifier{"ns"})
return v
}
// v1 -> v2
md, _ := view.NewMetadataBuilder().
SetLoc("s3://bucket/view").
SetCurrentVersion(version(1, "select * from ns.tbl"), sc).
Build()
b, _ := view.MetadataBuilderFromBase(md.Metadata)
md, _ = b.SetCurrentVersion(version(2, "select count(*) from ns.tbl"),
sc).Build()
// Replace the view with the first definition again.
b, _ = view.MetadataBuilderFromBase(md.Metadata)
_, err := b.SetCurrentVersion(version(3, "select * from ns.tbl"), sc).Build()
fmt.Println(err)
```
Output:
```
invalid view metadata: duplicate version-id 1
```
Expected: the result reuses version 1, makes it current, and the only change
is `set-current-view-version` with version ID 1.
**Cause:** `addVersion` in `view/metadata_builder.go` calls
`reuseOrCreateNewVersionID`, which finds the matching version 1. But it only
returns early if version 1 was added by an update in the current builder. A
version from the base metadata gets appended a second time, and `Build` then
rejects the duplicate ID.
**Java:** `ViewMetadata.Builder.addVersionInternal` returns the existing ID
whenever `versionsById` already contains it. It sets `lastAddedVersionId` only
if the version was added in this builder, and otherwise clears it.
**Proposed fix:** do the same in `addVersion`: return the existing ID for
any known version, and set `lastAddedVersionID` only when the version was added
in this builder.
I'd like to work on this. I have a fix and a unit test ready.
--
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]