You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by ze...@apache.org on 2026/10/23 23:02:26 UTC

(iceberg-go) branch main updated: refactor(view)!: rename Representation.Sql to SQL before v1 (#2283)

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 b7792e9e8 refactor(view)!: rename Representation.Sql to SQL before v1 (#2283)
b7792e9e8 is described below

commit b7792e9e8799664f2ca8cd7f4ea94c97515c9833
Author: Minh Vu <vu...@gmail.com>
AuthorDate: Sat Oct 24 01:02:20 2026 +0200

    refactor(view)!: rename Representation.Sql to SQL before v1 (#2283)
    
    * refactor(view)!: rename Representation.Sql to SQL before v1
    
    Signed-off-by: Minh Vu <vu...@gmail.com>
    
    * docs(releases): note pre-v1 breaking API migration
    
    * test(view): use Representation.SQL in input-copy test
    
    ---------
    
    Signed-off-by: Minh Vu <vu...@gmail.com>
    Co-authored-by: Matt Topol <zo...@gmail.com>
---
 catalog/hive/hive.go                  |  4 ++--
 catalog/hive/hive_integration_test.go |  2 +-
 catalog/rest/rest_test.go             |  4 ++--
 view/metadata.go                      |  6 +++---
 view/metadata_builder_test.go         | 32 ++++++++++++++++----------------
 view/metadata_test.go                 | 18 ++++++++++++++++--
 website/src/releases.md               |  1 +
 7 files changed, 41 insertions(+), 26 deletions(-)

diff --git a/catalog/hive/hive.go b/catalog/hive/hive.go
index 209247ec9..0cc298968 100644
--- a/catalog/hive/hive.go
+++ b/catalog/hive/hive.go
@@ -410,10 +410,10 @@ func sqlFromVersion(v *view.Version) (string, error) {
 			continue
 		}
 		if strings.EqualFold(r.Dialect, "hive") {
-			return r.Sql, nil
+			return r.SQL, nil
 		}
 		if fallback == "" {
-			fallback = r.Sql
+			fallback = r.SQL
 		}
 	}
 	if fallback != "" {
diff --git a/catalog/hive/hive_integration_test.go b/catalog/hive/hive_integration_test.go
index 199aaa9ca..a5202f154 100644
--- a/catalog/hive/hive_integration_test.go
+++ b/catalog/hive/hive_integration_test.go
@@ -475,7 +475,7 @@ func TestHiveIntegrationCreateView(t *testing.T) {
 	assert.True(schema.Equals(loaded.CurrentSchema()))
 	assert.Len(loaded.CurrentVersion().Representations, 1)
 	assert.Equal("sql", loaded.CurrentVersion().Representations[0].Type)
-	assert.Equal(viewSQL, loaded.CurrentVersion().Representations[0].Sql)
+	assert.Equal(viewSQL, loaded.CurrentVersion().Representations[0].SQL)
 }
 
 func TestHiveIntegrationCreateViewThenDrop(t *testing.T) {
diff --git a/catalog/rest/rest_test.go b/catalog/rest/rest_test.go
index ee38c1a7c..8c36e52a4 100644
--- a/catalog/rest/rest_test.go
+++ b/catalog/rest/rest_test.go
@@ -3655,7 +3655,7 @@ func (r *RestCatalogSuite) TestRegisterView200() {
 	r.Equal(metadataLoc, v.MetadataLocation())
 	r.Equal(uuid.MustParse("a1b2c3d4-e5f6-7890-1234-567890abcdef"), v.Metadata().ViewUUID())
 	r.EqualValues(1, v.Metadata().CurrentVersionID())
-	r.Equal(exampleViewSQL, v.Metadata().CurrentVersion().Representations[0].Sql)
+	r.Equal(exampleViewSQL, v.Metadata().CurrentVersion().Representations[0].SQL)
 }
 
 func (r *RestCatalogSuite) TestRegisterViewLabels() {
@@ -3865,7 +3865,7 @@ func (r *RestCatalogSuite) TestRenameView204() {
 	r.Equal(toIdent, renamed.Identifier())
 	r.Equal(metadataLoc, renamed.MetadataLocation())
 	r.Equal(uuid.MustParse("a1b2c3d4-e5f6-7890-1234-567890abcdef"), renamed.Metadata().ViewUUID())
-	r.Equal(exampleViewSQL, renamed.Metadata().CurrentVersion().Representations[0].Sql)
+	r.Equal(exampleViewSQL, renamed.Metadata().CurrentVersion().Representations[0].SQL)
 }
 
 func (r *RestCatalogSuite) TestRenameView404() {
diff --git a/view/metadata.go b/view/metadata.go
index 2c0af1c1a..a3e659c4b 100644
--- a/view/metadata.go
+++ b/view/metadata.go
@@ -103,7 +103,7 @@ type Representation struct {
 	// Must be sql
 	Type string `json:"type"`
 	// A SQL SELECT statement
-	Sql string `json:"sql"`
+	SQL string `json:"sql"`
 	// The dialect of the sql SELECT statement (e.g., "trino" or "spark")
 	Dialect string `json:"dialect"`
 }
@@ -112,7 +112,7 @@ type Representations []Representation
 func NewRepresentation(sql string, dialect string) Representation {
 	return Representation{
 		Type:    "sql",
-		Sql:     sql,
+		SQL:     sql,
 		Dialect: dialect,
 	}
 }
@@ -210,7 +210,7 @@ func validateRepresentation(repr Representation) (string, error) {
 		return "", errors.New("invalid view representation: type should be \"sql\"")
 	}
 
-	if strings.TrimSpace(repr.Sql) == "" {
+	if strings.TrimSpace(repr.SQL) == "" {
 		return "", errors.New("invalid view representation: sql is required")
 	}
 
diff --git a/view/metadata_builder_test.go b/view/metadata_builder_test.go
index b9c1d9066..2b80ba523 100644
--- a/view/metadata_builder_test.go
+++ b/view/metadata_builder_test.go
@@ -188,43 +188,43 @@ func TestNewVersion_RepresentationValidation(t *testing.T) {
 		{
 			name: "valid",
 			representations: Representations{
-				{Type: "sql", Sql: "SELECT 1", Dialect: "spark"},
+				{Type: "sql", SQL: "SELECT 1", Dialect: "spark"},
 			},
 		},
 		{
 			name: "invalid type",
 			representations: Representations{
-				{Type: "hive", Sql: "SELECT 1", Dialect: "spark"},
+				{Type: "hive", SQL: "SELECT 1", Dialect: "spark"},
 			},
 			wantErr: "type should be \"sql\"",
 		},
 		{
 			name: "missing sql",
 			representations: Representations{
-				{Type: "sql", Sql: "", Dialect: "spark"},
+				{Type: "sql", SQL: "", Dialect: "spark"},
 			},
 			wantErr: "sql is required",
 		},
 		{
 			name: "missing dialect",
 			representations: Representations{
-				{Type: "sql", Sql: "SELECT 1", Dialect: ""},
+				{Type: "sql", SQL: "SELECT 1", Dialect: ""},
 			},
 			wantErr: "dialect is required",
 		},
 		{
 			name: "duplicate dialect",
 			representations: Representations{
-				{Type: "sql", Sql: "SELECT 1", Dialect: "SpArK"},
-				{Type: "sql", Sql: "SELECT 2", Dialect: " spark "},
+				{Type: "sql", SQL: "SELECT 1", Dialect: "SpArK"},
+				{Type: "sql", SQL: "SELECT 2", Dialect: " spark "},
 			},
 			wantErr: "Cannot add multiple queries for dialect  spark ",
 		},
 		{
 			name: "valid then invalid type",
 			representations: Representations{
-				{Type: "sql", Sql: "SELECT 1", Dialect: "spark"},
-				{Type: "hive", Sql: "SELECT 2", Dialect: "hive"},
+				{Type: "sql", SQL: "SELECT 1", Dialect: "spark"},
+				{Type: "hive", SQL: "SELECT 2", Dialect: "hive"},
 			},
 			wantErr: "type should be \"sql\"",
 		},
@@ -258,7 +258,7 @@ func TestNewVersionCopiesInputSlices(t *testing.T) {
 
 	// These mutations would otherwise change an already validated version,
 	// including making the representation dialects duplicate.
-	representations[0].Sql = "SELECT changed"
+	representations[0].SQL = "SELECT changed"
 	representations[1].Dialect = "spark"
 	defaultNS[0] = "other"
 	defaultNS[1] = "schema"
@@ -270,9 +270,9 @@ func TestNewVersionCopiesInputSlices(t *testing.T) {
 	assert.Equal(t, table.Identifier{"analytics", "reporting"}, version.DefaultNamespace)
 
 	// Neither side should share the backing storage with the other.
-	version.Representations[0].Sql = "SELECT from version"
+	version.Representations[0].SQL = "SELECT from version"
 	version.DefaultNamespace[0] = "version"
-	assert.Equal(t, "SELECT changed", representations[0].Sql)
+	assert.Equal(t, "SELECT changed", representations[0].SQL)
 	assert.Equal(t, "other", defaultNS[0])
 }
 
@@ -290,7 +290,7 @@ func TestAddVersion_InvalidRepresentation_Validation(t *testing.T) {
 		VersionID: 1,
 		SchemaID:  0,
 		Representations: []Representation{
-			{Type: "hive", Sql: "SELECT 1", Dialect: "spark"},
+			{Type: "hive", SQL: "SELECT 1", Dialect: "spark"},
 		},
 	}
 
@@ -308,8 +308,8 @@ func TestAddVersion_InvalidRepresentation_Validation(t *testing.T) {
 		VersionID: 2,
 		SchemaID:  0,
 		Representations: []Representation{
-			{Type: "sql", Sql: "SELECT 1", Dialect: "spark"},
-			{Type: "sql", Sql: "SELECT 2", Dialect: "spark "},
+			{Type: "sql", SQL: "SELECT 1", Dialect: "spark"},
+			{Type: "sql", SQL: "SELECT 2", Dialect: "spark "},
 		},
 	}
 
@@ -693,8 +693,8 @@ func TestAddVersion_MultipleSQLForSameDialect(t *testing.T) {
 		VersionID: 1,
 		SchemaID:  0,
 		Representations: []Representation{
-			{Type: "sql", Sql: "select * from ns.tbl", Dialect: "spark"},
-			{Type: "sql", Sql: "select * from ns.tbl3", Dialect: "SpArK"},
+			{Type: "sql", SQL: "select * from ns.tbl", Dialect: "spark"},
+			{Type: "sql", SQL: "select * from ns.tbl3", Dialect: "SpArK"},
 		},
 	}
 	_, err := newTestBuilder().
diff --git a/view/metadata_test.go b/view/metadata_test.go
index b0f1200ed..9d63a86c4 100644
--- a/view/metadata_test.go
+++ b/view/metadata_test.go
@@ -69,6 +69,20 @@ func TestVersionEquals(t *testing.T) {
 	assert.True(t, v1.Equals(v2), fmt.Sprintf("Expected the same SchemaID, Summary, Representation for %v, got %v", v1, v2))
 }
 
+// TestRepresentationSQLJSON keeps the on-disk SQL key unchanged after the Go API rename.
+func TestRepresentationSQLJSON(t *testing.T) {
+	repr := NewRepresentation("SELECT 1", "spark")
+	require.Equal(t, "SELECT 1", repr.SQL)
+
+	data, err := json.Marshal(repr)
+	require.NoError(t, err)
+	assert.JSONEq(t, `{"type":"sql","sql":"SELECT 1","dialect":"spark"}`, string(data))
+
+	var decoded Representation
+	require.NoError(t, json.Unmarshal(data, &decoded))
+	assert.Equal(t, repr, decoded)
+}
+
 func TestNewMetadata(t *testing.T) {
 	// VersionID of 3 should be overridden by the ViewMD ctor
 	version := newTestVersion(3, LastAddedID,
@@ -675,7 +689,7 @@ func TestMetadataGettersReturnDefensiveCopies(t *testing.T) {
 
 	currentVersion := md.CurrentVersion()
 	currentVersion.Summary["summaryProp"] = "changed"
-	currentVersion.Representations[0].Sql = "select changed"
+	currentVersion.Representations[0].SQL = "select changed"
 	currentVersion.DefaultNamespace[0] = "changed"
 
 	versions := md.Versions()
@@ -700,7 +714,7 @@ func TestMetadataGettersReturnDefensiveCopies(t *testing.T) {
 
 	assert.Equal(t, int64(1), md.CurrentVersion().VersionID)
 	assert.Equal(t, "summaryVal", md.CurrentVersion().Summary["summaryProp"])
-	assert.Equal(t, "select * from ns.tbl", md.CurrentVersion().Representations[0].Sql)
+	assert.Equal(t, "select * from ns.tbl", md.CurrentVersion().Representations[0].SQL)
 	assert.Equal(t, "accounting", md.CurrentVersion().DefaultNamespace[0])
 	assert.Equal(t, 0, md.CurrentSchema().ID)
 	assert.Equal(t, 0, md.CurrentSchema().IdentifierFieldIDs[0])
diff --git a/website/src/releases.md b/website/src/releases.md
index 435ec5148..8dc9053cb 100644
--- a/website/src/releases.md
+++ b/website/src/releases.md
@@ -42,6 +42,7 @@ Per-release notes (highlights, breaking changes, contributors) are published on
 
 ### Unreleased compatibility notes
 
+- **View representation field uses the Go SQL initialism.** Replace `view.Representation.Sql` with `view.Representation.SQL`. Serialized view metadata still uses the `sql` JSON field.
 - **Orphan cleanup results now expose only `OrphanFiles`.** Replace `result.OrphanFileLocations` with `result.OrphanFiles` (each entry has `Path` and `SizeBytes`). `OrphanCleanupPlan.Files()` still provides path-only lists during planning.
 - **Catalog identifier helper renamed.** `catalog.TableNameFromIdent` is removed. Use `catalog.ObjectNameFromIdent` for tables, views, and functions.
 - **Substrait expression conversion no longer takes case sensitivity.** `substrait.ConvertExpr(schema, expression, caseSensitive)` becomes `substrait.ConvertExpr(schema, expression)`. Case sensitivity remains part of expression binding.