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 c3d4bfc5 fix(view): field ID preservation and error handling for RCK 
compatibility (#647)
c3d4bfc5 is described below

commit c3d4bfc524a83f1c2b79ed397c1b46757cf23d30
Author: Shubhendu <[email protected]>
AuthorDate: Tue Dec 9 22:54:55 2025 +0530

    fix(view): field ID preservation and error handling for RCK compatibility 
(#647)
    
    1. Field ID Reassignment: NewMetadataWithUUID() was calling
    iceberg.AssignFreshSchemaIDs() which reassigned all field IDs starting
    from 1, breaking clients that expect their original field IDs to be
    preserved.
    2. Error Message Format: Duplicate dialect validation error wasn't
    wrapped with ErrInvalidViewMetadata and lacked proper capitalization,
    preventing MinIO from mapping it to IllegalArgumentException.
    3. Schema ID Handling: While MetadataBuilder.addSchema() already
    normalizes schema IDs to 0 for new views, the test expected consistent
    behavior across view version updates.
    
    ## Problem it solves
    Three RCK (REST Compatibility Kit) view tests were failing:
    1. basicCreateView / completeCreateView: Field ID mismatch
    expected: struct<3: id: required int, 4: data: required string>
    but was:  struct<1: id: required int, 2: data: required string>
    2. createViewErrorCases: Incorrect error message format
    Expected: "Invalid view version: Cannot add multiple queries for dialect
    trino"
    Actual:   "cannot add multiple queries for dialect trino"
    3. concurrentReplaceViewVersion: Schema ID not normalized
    expected: schemaId=0
    but was:  schemaId=2
    
    Signed-off-by: Shubhendu Ram Tripathi <[email protected]>
---
 view/metadata.go              | 9 ++++-----
 view/metadata_builder.go      | 2 +-
 view/metadata_builder_test.go | 2 +-
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/view/metadata.go b/view/metadata.go
index ed69ac0d..06590c71 100644
--- a/view/metadata.go
+++ b/view/metadata.go
@@ -511,10 +511,8 @@ func NewMetadata(version *Version, sc *iceberg.Schema, 
location string, props ic
 
 // NewMetadataWithUUID is like NewMetadata, but allows the caller to specify 
the UUID of the view rather than creating a new one.
 func NewMetadataWithUUID(version *Version, sc *iceberg.Schema, location 
string, props iceberg.Properties, viewUUID uuid.UUID) (Metadata, error) {
-       freshSchema, err := iceberg.AssignFreshSchemaIDs(sc, nil)
-       if err != nil {
-               return nil, err
-       }
+       // Don't call AssignFreshSchemaIDs here as it reassigns field IDs which 
breaks RCK tests.
+       // The MetadataBuilder.SetCurrentVersion method will handle schema ID 
normalization.
 
        if viewUUID == uuid.Nil {
                viewUUID = uuid.New()
@@ -524,6 +522,7 @@ func NewMetadataWithUUID(version *Version, sc 
*iceberg.Schema, location string,
        if props != nil {
                verStr, ok := props["format-version"]
                if ok {
+                       var err error
                        if formatVersion, err = strconv.Atoi(verStr); err != 
nil {
                                formatVersion = DefaultViewFormatVersion
                        }
@@ -549,6 +548,6 @@ func NewMetadataWithUUID(version *Version, sc 
*iceberg.Schema, location string,
                SetUUID(viewUUID).
                SetLoc(location).
                SetProperties(props).
-               SetCurrentVersion(version, freshSchema).
+               SetCurrentVersion(version, sc).
                Build()
 }
diff --git a/view/metadata_builder.go b/view/metadata_builder.go
index 7a6afbf3..85b21b4d 100644
--- a/view/metadata_builder.go
+++ b/view/metadata_builder.go
@@ -183,7 +183,7 @@ func (b *MetadataBuilder) addVersion(newVersion *Version) 
(int64, error) {
        for _, repr := range version.Representations {
                normalizedDialect := strings.ToLower(repr.Dialect)
                if _, ok := dialects[normalizedDialect]; ok {
-                       return 0, fmt.Errorf("invalid view version: cannot add 
multiple queries for dialect %s", normalizedDialect)
+                       return 0, fmt.Errorf("%w: Invalid view version: Cannot 
add multiple queries for dialect %s", ErrInvalidViewMetadata, normalizedDialect)
                }
                dialects[normalizedDialect] = struct{}{}
        }
diff --git a/view/metadata_builder_test.go b/view/metadata_builder_test.go
index fa6f6c26..418fb05d 100644
--- a/view/metadata_builder_test.go
+++ b/view/metadata_builder_test.go
@@ -473,7 +473,7 @@ func TestAddVersion_MultipleSQLForSameDialect(t *testing.T) 
{
                ).
                SetCurrentVersionID(1).
                Build()
-       assert.ErrorContains(t, err, "invalid view version: cannot add multiple 
queries for dialect spark")
+       assert.ErrorContains(t, err, "Invalid view version: Cannot add multiple 
queries for dialect spark")
 }
 
 func TestSetCurrentVersionID_NoLastAddedSchema(t *testing.T) {

Reply via email to