laskoviymishka commented on code in PR #2698:
URL: https://github.com/apache/iceberg-go/pull/2698#discussion_r4722342534


##########
catalog/catalogtest/create_table_opts.go:
##########
@@ -0,0 +1,104 @@
+// 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
+}
+
+// testCreateTableWithPartitionSpec asserts that the partition spec passed at
+// create time is the table's spec on a fresh load, allowing for reassigned
+// spec, field and source IDs.
+func testCreateTableWithPartitionSpec(t *testing.T, cfg Config) {
+       ctx := context.Background()
+       cat := cfg.NewCatalog(t)
+
+       spec, err := iceberg.NewPartitionSpecOpts(
+               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()

Review Comment:
   Fixed in 8fcbddde68



##########
catalog/catalogtest/create_table_opts.go:
##########
@@ -0,0 +1,104 @@
+// 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
+}
+
+// testCreateTableWithPartitionSpec asserts that the partition spec passed at
+// create time is the table's spec on a fresh load, allowing for reassigned
+// spec, field and source IDs.
+func testCreateTableWithPartitionSpec(t *testing.T, cfg Config) {
+       ctx := context.Background()
+       cat := cfg.NewCatalog(t)
+
+       spec, err := iceberg.NewPartitionSpecOpts(
+               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()
+       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, 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, allowing for reassigned
+// order and source IDs.
+func testCreateTableWithSortOrder(t *testing.T, cfg Config) {
+       ctx := context.Background()
+       cat := cfg.NewCatalog(t)
+
+       order, err := table.NewSortOrder(1, []table.SortField{

Review Comment:
   Fixed in 8fcbddde68



-- 
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]

Reply via email to