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 8f7644211 test(catalogtest): cover CreateTable with a partition spec 
and a sort order (#2698)
8f7644211 is described below

commit 8f76442118937909ff0025419cdc9f7b0a39bbbb
Author: Andrei Tserakhau <[email protected]>
AuthorDate: Fri Nov 27 22:49:23 2026 +0100

    test(catalogtest): cover CreateTable with a partition spec and a sort order 
(#2698)
    
    The conformance suite only called CreateTable with WithProperties. Add
    CreateTableWithPartitionSpec and CreateTableWithSortOrder, following
    Java's CatalogTests.testCompleteCreateTable: create the table with
    WithPartitionSpec or WithSortOrder, load it again, and check the spec or
    order against what was passed.
    
    The partition spec uses bucket(16) on id and identity on data; the sort
    order uses data asc nulls-first and bucket(16) on id desc nulls-last.
    Catalogs assign fresh IDs on create, so fields are compared by name,
    transform, direction and null order, and each source ID is resolved to
    its column name in the loaded schema instead of comparing raw IDs.
    
    WithLocation is left for a later slice, since the location a server
    accepts differs per catalog.
---
 catalog/catalogtest/catalogtest.go       |   2 +
 catalog/catalogtest/commits.go           |  13 ----
 catalog/catalogtest/create_table_opts.go | 118 +++++++++++++++++++++++++++++++
 3 files changed, 120 insertions(+), 13 deletions(-)

diff --git a/catalog/catalogtest/catalogtest.go 
b/catalog/catalogtest/catalogtest.go
index 0d97e6b1a..74092b3cb 100644
--- a/catalog/catalogtest/catalogtest.go
+++ b/catalog/catalogtest/catalogtest.go
@@ -139,6 +139,8 @@ func RunCatalogTests(t *testing.T, cfg Config) {
        t.Run("UpdateTableSchema", func(t *testing.T) { 
testUpdateTableSchema(t, cfg) })
        t.Run("CommitWithStaleRequirement", func(t *testing.T) { 
testCommitWithStaleRequirement(t, cfg) })
        t.Run("CommitToDroppedTable", func(t *testing.T) { 
testCommitToDroppedTable(t, cfg) })
+       t.Run("CreateTableWithPartitionSpec", func(t *testing.T) { 
testCreateTableWithPartitionSpec(t, cfg) })
+       t.Run("CreateTableWithSortOrder", func(t *testing.T) { 
testCreateTableWithSortOrder(t, cfg) })
 
        t.Run("CreateNamespace", func(t *testing.T) { testCreateNamespace(t, 
cfg) })
        t.Run("CreateNamespaceThatAlreadyExists", func(t *testing.T) { 
testCreateNamespaceThatAlreadyExists(t, cfg) })
diff --git a/catalog/catalogtest/commits.go b/catalog/catalogtest/commits.go
index 6b12c3552..c96ef78c9 100644
--- a/catalog/catalogtest/commits.go
+++ b/catalog/catalogtest/commits.go
@@ -46,19 +46,6 @@ func createTable(t *testing.T, cat catalog.Catalog, opts 
...catalog.CreateTableO
        return ident, tbl
 }
 
-// testCreateTableWithProperties asserts that properties passed at create time
-// are visible on a fresh load.
-func testCreateTableWithProperties(t *testing.T, cfg Config) {
-       ctx := context.Background()
-       cat := cfg.NewCatalog(t)
-
-       ident, _ := createTable(t, cat, 
catalog.WithProperties(iceberg.Properties{"owner": "conformance"}))
-
-       tbl, err := cat.LoadTable(ctx, ident)
-       require.NoError(t, err)
-       assert.Equal(t, "conformance", tbl.Properties()["owner"])
-}
-
 // testUpdateTableProperties asserts that properties set and removed through a
 // transaction are visible on a fresh load.
 func testUpdateTableProperties(t *testing.T, cfg Config) {
diff --git a/catalog/catalogtest/create_table_opts.go 
b/catalog/catalogtest/create_table_opts.go
new file mode 100644
index 000000000..dd0dfb350
--- /dev/null
+++ b/catalog/catalogtest/create_table_opts.go
@@ -0,0 +1,118 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package catalogtest
+
+import (
+       "context"
+       "testing"
+
+       "github.com/apache/iceberg-go"
+       "github.com/apache/iceberg-go/catalog"
+       "github.com/apache/iceberg-go/table"
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+)
+
+// sourceName returns the name of the column a partition or sort field reads
+// from. Catalogs assign fresh field IDs on create, so fields are matched to
+// what was passed by column name rather than by ID.
+func sourceName(t *testing.T, schema *iceberg.Schema, sourceIDs []int) string {
+       t.Helper()
+
+       require.Len(t, sourceIDs, 1)
+       name, ok := schema.FindColumnName(sourceIDs[0])
+       require.Truef(t, ok, "source ID %d should be in the schema", 
sourceIDs[0])
+
+       return name
+}
+
+// testCreateTableWithProperties asserts that properties passed at create time
+// are visible on a fresh load.
+func testCreateTableWithProperties(t *testing.T, cfg Config) {
+       ctx := context.Background()
+       cat := cfg.NewCatalog(t)
+
+       ident, _ := createTable(t, cat, 
catalog.WithProperties(iceberg.Properties{"owner": "conformance"}))
+
+       tbl, err := cat.LoadTable(ctx, ident)
+       require.NoError(t, err)
+       assert.Equal(t, "conformance", tbl.Properties()["owner"])
+}
+
+// testCreateTableWithPartitionSpec asserts that the partition spec passed at
+// create time is the table's spec on a fresh load, with fresh spec and field
+// IDs assigned.
+func testCreateTableWithPartitionSpec(t *testing.T, cfg Config) {
+       ctx := context.Background()
+       cat := cfg.NewCatalog(t)
+
+       spec, err := iceberg.NewPartitionSpecOpts(
+               iceberg.WithSpecID(3),
+               iceberg.AddPartitionFieldByName("id", "id_bucket", 
iceberg.BucketTransform{NumBuckets: 16}, Schema, nil),
+               iceberg.AddPartitionFieldByName("data", "data", 
iceberg.IdentityTransform{}, Schema, nil),
+       )
+       require.NoError(t, err)
+
+       ident, _ := createTable(t, cat, catalog.WithPartitionSpec(&spec))
+
+       tbl, err := cat.LoadTable(ctx, ident)
+       require.NoError(t, err)
+
+       loaded := tbl.Spec()
+       assert.Equal(t, iceberg.InitialPartitionSpecID, loaded.ID())
+       require.Equal(t, spec.NumFields(), loaded.NumFields(), "loaded spec 
should have the fields it was created with")
+       for i := range spec.NumFields() {
+               want, got := spec.Field(i), loaded.Field(i)
+               assert.Equal(t, iceberg.PartitionDataIDStart+i, got.FieldID)
+               assert.Equal(t, want.Name, got.Name)
+               assert.Equal(t, want.Transform, got.Transform)
+               assert.Equal(t, sourceName(t, Schema, want.SourceIDs), 
sourceName(t, tbl.Schema(), got.SourceIDs))
+       }
+}
+
+// testCreateTableWithSortOrder asserts that the sort order passed at create
+// time is the table's sort order on a fresh load, with a fresh order ID
+// assigned.
+func testCreateTableWithSortOrder(t *testing.T, cfg Config) {
+       ctx := context.Background()
+       cat := cfg.NewCatalog(t)
+
+       order, err := table.NewSortOrder(5, []table.SortField{
+               {SourceIDs: []int{4}, Transform: iceberg.IdentityTransform{}, 
Direction: table.SortASC, NullOrder: table.NullsFirst},
+               {SourceIDs: []int{3}, Transform: 
iceberg.BucketTransform{NumBuckets: 16}, Direction: table.SortDESC, NullOrder: 
table.NullsLast},
+       })
+       require.NoError(t, err)
+
+       ident, _ := createTable(t, cat, catalog.WithSortOrder(order))
+
+       tbl, err := cat.LoadTable(ctx, ident)
+       require.NoError(t, err)
+
+       loaded := tbl.SortOrder()
+       require.False(t, loaded.IsUnsorted(), "loaded table should be sorted")
+       assert.Equal(t, table.InitialSortOrderID, loaded.OrderID())
+       require.Equal(t, order.Len(), loaded.Len(), "loaded sort order should 
have the fields it was created with")
+
+       for i, got := range loaded.Fields() {
+               want := order.Field(i)
+               assert.Equal(t, want.Direction, got.Direction)
+               assert.Equal(t, want.NullOrder, got.NullOrder)
+               assert.Equal(t, want.Transform, got.Transform)
+               assert.Equal(t, sourceName(t, Schema, want.SourceIDs), 
sourceName(t, tbl.Schema(), got.SourceIDs))
+       }
+}

Reply via email to