You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by at...@apache.org on 2026/06/25 08:01:19 UTC

(iceberg-go) branch main updated: test: pin geo type JSON wire format (#1284)

This is an automated email from the ASF dual-hosted git repository.

laskoviymishka 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 8a8556b0 test: pin geo type JSON wire format (#1284)
8a8556b0 is described below

commit 8a8556b0e0011b867116bb661e5c2d8a22e85103
Author: Revanth <re...@gmail.com>
AuthorDate: Thu Jun 25 03:01:13 2026 -0500

    test: pin geo type JSON wire format (#1284)
    
    ## Summary
    
    Adds a cross-implementation schema JSON fixture to pin the Iceberg geo
    type-string wire format.
    
    The fixture includes:
    
    - `geometry(srid:3857)`
    - `geography(srid:4269, karney)`
    
    The new test loads the fixture, unmarshals and re-marshals it through
    Go, then compares the raw emitted JSON `type` string literals
    byte-for-byte instead of using `assert.JSONEq`.
    
    ## Why
    
    Existing geo tests validated JSON equivalence, but did not pin the exact
    type strings that other Iceberg clients parse. This locks the current
    wire format before more geo-related work builds on it.
    
    Fixes #1271.
    
    ## Testing
    
    ```sh
    go test ./...
---
 schema_test.go                     | 81 ++++++++++++++++++++++++++++++++++++++
 testdata/geo-schema-java-main.json |  1 +
 2 files changed, 82 insertions(+)

diff --git a/schema_test.go b/schema_test.go
index 846ea9b8..3763a7e1 100644
--- a/schema_test.go
+++ b/schema_test.go
@@ -19,6 +19,8 @@ package iceberg_test
 
 import (
 	"encoding/json"
+	"os"
+	"path/filepath"
 	"strings"
 	"testing"
 
@@ -28,6 +30,33 @@ import (
 	"github.com/stretchr/testify/require"
 )
 
+// geoSchemaJavaFixtureName is a schema JSON fixture emitted by Apache Iceberg
+// Java SchemaParser.toJson. Geometry and geography support was added in
+// apache/iceberg commit e1e0a740 (#12346) and the geo type-string format was
+// last touched in 8de302bf when this fixture was captured.
+//
+// Source schema:
+//
+//	new Schema(17, ImmutableList.of(
+//	    Types.NestedField.required(1, "id", Types.LongType.get()),
+//	    Types.NestedField.optional(2, "geom", Types.GeometryType.of("srid:3857")),
+//	    Types.NestedField.optional(3, "geog",
+//	        Types.GeographyType.of("srid:4269", EdgeAlgorithm.KARNEY)),
+//	    Types.NestedField.optional(4, "geog_default_algo",
+//	        Types.GeographyType.of("srid:4269")),
+//	    Types.NestedField.optional(5, "geog_default_crs",
+//	        Types.GeographyType.of("OGC:CRS84", EdgeAlgorithm.KARNEY)),
+//	    Types.NestedField.optional(6, "geom_default",
+//	        Types.GeometryType.crs84()),
+//	    Types.NestedField.optional(7, "geog_default",
+//	        Types.GeographyType.crs84())))
+//
+// Java and Go write object keys in different orders, so the fixture test pins
+// the raw JSON string literals for field types instead of whole-object bytes.
+// PyIceberg currently emits quoted CRS values like geometry('srid:3857'), so
+// this fixture is scoped specifically to Java's type-string form.
+const geoSchemaJavaFixtureName = "geo-schema-java-main.json"
+
 var (
 	tableSchemaNested = iceberg.NewSchemaWithIdentifiers(1,
 		[]int{1},
@@ -1177,6 +1206,58 @@ func TestSchemaWithGeometryGeographyTypes(t *testing.T) {
 	assert.True(t, schema.Equals(&unmarshaledSchema))
 }
 
+func TestSchemaGeoTypeStringWireFormatFixture(t *testing.T) {
+	fixtureBytes, err := os.ReadFile(filepath.Join("testdata", geoSchemaJavaFixtureName))
+	require.NoError(t, err, "fixture missing")
+
+	var schema iceberg.Schema
+	require.NoError(t, json.Unmarshal(fixtureBytes, &schema))
+
+	freshBytes, err := json.Marshal(&schema)
+	require.NoError(t, err)
+
+	fixtureTypes := rawTopLevelFieldTypes(t, fixtureBytes)
+	freshTypes := rawTopLevelFieldTypes(t, freshBytes)
+	expectedTypes := map[string]string{
+		"id":                `"long"`,
+		"geom":              `"geometry(srid:3857)"`,
+		"geog":              `"geography(srid:4269, karney)"`,
+		"geog_default_algo": `"geography(srid:4269)"`,
+		"geog_default_crs":  `"geography(OGC:CRS84, karney)"`,
+		"geom_default":      `"geometry"`,
+		"geog_default":      `"geography"`,
+	}
+	require.Len(t, fixtureTypes, len(expectedTypes))
+	require.Len(t, freshTypes, len(expectedTypes))
+	for fieldName, expected := range expectedTypes {
+		require.Equalf(t, expected, fixtureTypes[fieldName], "fixture field %q type", fieldName)
+		assert.Equalf(t, expected, freshTypes[fieldName], "fresh field %q type", fieldName)
+	}
+}
+
+func rawTopLevelFieldTypes(t *testing.T, data []byte) map[string]string {
+	t.Helper()
+
+	var schema struct {
+		Fields []struct {
+			Name string          `json:"name"`
+			Type json.RawMessage `json:"type"`
+		} `json:"fields"`
+	}
+	require.NoError(t, json.Unmarshal(data, &schema))
+	require.NotEmpty(t, schema.Fields)
+
+	types := make(map[string]string, len(schema.Fields))
+	for _, field := range schema.Fields {
+		require.NotEmpty(t, field.Name)
+		require.NotEmptyf(t, field.Type, "field %q is missing type", field.Name)
+		require.NotEqualf(t, "null", string(field.Type), "field %q is missing type", field.Name)
+		types[field.Name] = string(field.Type)
+	}
+
+	return types
+}
+
 func TestNestedFieldToStringGeographyGeometry(t *testing.T) {
 	geom, err := iceberg.GeometryTypeOf("srid:3857")
 	require.NoError(t, err)
diff --git a/testdata/geo-schema-java-main.json b/testdata/geo-schema-java-main.json
new file mode 100644
index 00000000..703efe65
--- /dev/null
+++ b/testdata/geo-schema-java-main.json
@@ -0,0 +1 @@
+{"type":"struct","schema-id":17,"fields":[{"id":1,"name":"id","required":true,"type":"long"},{"id":2,"name":"geom","required":false,"type":"geometry(srid:3857)"},{"id":3,"name":"geog","required":false,"type":"geography(srid:4269, karney)"},{"id":4,"name":"geog_default_algo","required":false,"type":"geography(srid:4269)"},{"id":5,"name":"geog_default_crs","required":false,"type":"geography(OGC:CRS84, karney)"},{"id":6,"name":"geom_default","required":false,"type":"geometry"},{"id":7,"name [...]