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 0657b31dd test(catalogtest): cover nested namespaces (#2389)
0657b31dd is described below

commit 0657b31dd3b84e30b47e65295f7bfbdf79549a83
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sun Nov 15 21:24:32 2026 +0100

    test(catalogtest): cover nested namespaces (#2389)
---
 .github/workflows/go-integration.yml      |   2 +
 CONTRIBUTING.md                           |   2 +
 catalog/catalogtest/catalogtest.go        |  13 ++++
 catalog/catalogtest/namespaces.go         | 110 +++++++++++++++++++++++++++++-
 catalog/hadoop/conformance_test.go        |   1 +
 catalog/rest/conformance_test.go          |   5 ++
 catalog/rest/external_conformance_test.go |  16 +++++
 catalog/sql/conformance_test.go           |   2 +
 8 files changed, 148 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/go-integration.yml 
b/.github/workflows/go-integration.yml
index 77e4e7958..2d9c08941 100644
--- a/.github/workflows/go-integration.yml
+++ b/.github/workflows/go-integration.yml
@@ -87,6 +87,8 @@ jobs:
       # conformance suite runs on one matrix leg only.
       - name: Run external REST catalog conformance tests (Apache Polaris)
         if: ${{ matrix.spark.version == '3.5' }}
+        env:
+          REST_CATALOG_NESTED_NAMESPACES: "true"
         run: |
           make integration-setup-polaris
           make integration-external-rest
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index f3bb96150..43c795246 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -85,3 +85,5 @@ To test another catalog, override the Polaris defaults with 
`REST_CATALOG_URI`,
 REST_CATALOG_URI=http://localhost:8181 REST_CATALOG_CREDENTIAL= 
REST_CATALOG_SCOPE= REST_CATALOG_WAREHOUSE= \
   make integration-external-rest
 ```
+
+The nested namespace tests are off by default. Set 
`REST_CATALOG_NESTED_NAMESPACES=true` to run them against a catalog that lists 
only direct children and refuses to drop a namespace with children; CI sets it 
for Polaris.
diff --git a/catalog/catalogtest/catalogtest.go 
b/catalog/catalogtest/catalogtest.go
index c97d8bce3..257344b91 100644
--- a/catalog/catalogtest/catalogtest.go
+++ b/catalog/catalogtest/catalogtest.go
@@ -96,6 +96,15 @@ type Config struct {
        // the rename tests are replaced by one asserting that RenameTable 
returns
        // iceberg.ErrNotImplemented and leaves the source table in place.
        SupportsRenameTable bool
+
+       // SupportsNestedNamespaces reports whether the catalog follows Java's
+       // nested namespace behavior: listing a namespace returns only its 
direct
+       // children, and a namespace that still has children cannot be dropped.
+       // When it is true, the suite checks both. It mirrors Java's
+       // supportsNestedNamespaces, which is false by default. Unlike the other
+       // flags it has no not-supported test: Hive and Glue reject nested
+       // namespaces with their own error, not iceberg.ErrNotImplemented.
+       SupportsNestedNamespaces bool
 }
 
 // RunCatalogTests runs the conformance suite against the catalog described by
@@ -135,6 +144,10 @@ func RunCatalogTests(t *testing.T, cfg Config) {
        t.Run("DropMissingNamespace", func(t *testing.T) { 
testDropMissingNamespace(t, cfg) })
        t.Run("DropNamespaceNotEmpty", func(t *testing.T) { 
testDropNamespaceNotEmpty(t, cfg) })
        t.Run("ListNamespaces", func(t *testing.T) { testListNamespaces(t, cfg) 
})
+       if cfg.SupportsNestedNamespaces {
+               t.Run("ListNestedNamespaces", func(t *testing.T) { 
testListNestedNamespaces(t, cfg) })
+               t.Run("DropNamespaceWithNestedNamespace", func(t *testing.T) { 
testDropNamespaceWithNestedNamespace(t, cfg) })
+       }
 
        t.Run("LoadNamespaceProperties", func(t *testing.T) { 
testLoadNamespaceProperties(t, cfg) })
        if cfg.SupportsNamespaceProperties {
diff --git a/catalog/catalogtest/namespaces.go 
b/catalog/catalogtest/namespaces.go
index b49dde99d..1dae416e9 100644
--- a/catalog/catalogtest/namespaces.go
+++ b/catalog/catalogtest/namespaces.go
@@ -18,9 +18,8 @@
 package catalogtest
 
 // This file covers namespaces: the structural lifecycle (create, exists, list,
-// drop) and properties (create with properties, load, set, update, remove).
-// Nested namespaces are deferred to a later slice of #1691, together with the
-// Config.SupportsNestedNamespaces flag that would gate them.
+// drop), nested namespaces when Config.SupportsNestedNamespaces is set, and
+// properties (create with properties, load, set, update, remove).
 //
 // Java splits property writes across SupportsNamespaces.setProperties and
 // removeProperties; the Go catalog has a single UpdateNamespaceProperties
@@ -29,10 +28,12 @@ package catalogtest
 
 import (
        "context"
+       "slices"
        "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"
 )
@@ -168,6 +169,109 @@ func testListNamespaces(t *testing.T, cfg Config) {
        assert.Contains(t, namespaces, second, "remaining namespace should 
still be listed")
 }
 
+// testListNestedNamespaces asserts that listing a namespace returns only its
+// direct children as full identifiers, never deeper descendants, that the
+// children stay out of the top-level listing, and that a dropped child
+// disappears from its parent's listing.
+func testListNestedNamespaces(t *testing.T, cfg Config) {
+       ctx := context.Background()
+       cat := cfg.NewCatalog(t)
+       parent, _ := newIdentifiers()
+       child1 := append(slices.Clone(parent), "child1")
+       child2 := append(slices.Clone(parent), "child2")
+       grandchild := append(slices.Clone(child1), "grandchild")
+
+       require.NoError(t, cat.CreateNamespace(ctx, parent, nil))
+       t.Cleanup(func() { _ = cat.DropNamespace(ctx, parent) })
+
+       children, err := cat.ListNamespaces(ctx, parent)
+       require.NoError(t, err)
+       assert.Empty(t, children, "a new namespace should have no children")
+
+       require.NoError(t, cat.CreateNamespace(ctx, child1, nil))
+       t.Cleanup(func() { _ = cat.DropNamespace(ctx, child1) })
+
+       children, err = cat.ListNamespaces(ctx, parent)
+       require.NoError(t, err)
+       assert.ElementsMatch(t, []table.Identifier{child1}, children, "listing 
the parent should return child1")
+
+       require.NoError(t, cat.CreateNamespace(ctx, child2, nil))
+       t.Cleanup(func() { _ = cat.DropNamespace(ctx, child2) })
+
+       children, err = cat.ListNamespaces(ctx, parent)
+       require.NoError(t, err)
+       assert.ElementsMatch(t, []table.Identifier{child1, child2}, children, 
"listing the parent should return both children")
+
+       require.NoError(t, cat.CreateNamespace(ctx, grandchild, nil))
+       t.Cleanup(func() { _ = cat.DropNamespace(ctx, grandchild) })
+
+       children, err = cat.ListNamespaces(ctx, parent)
+       require.NoError(t, err)
+       assert.ElementsMatch(t, []table.Identifier{child1, child2}, children, 
"listing the parent should return only its direct children, not the grandchild")
+
+       children, err = cat.ListNamespaces(ctx, child1)
+       require.NoError(t, err)
+       assert.ElementsMatch(t, []table.Identifier{grandchild}, children, 
"listing child1 should return the grandchild")
+
+       top, err := cat.ListNamespaces(ctx, nil)
+       require.NoError(t, err)
+       assert.Contains(t, top, parent, "the parent should be listed at the top 
level")
+       assert.NotContains(t, top, child1, "a child should not be listed at the 
top level")
+       assert.NotContains(t, top, child2, "a child should not be listed at the 
top level")
+       assert.NotContains(t, top, grandchild, "a grandchild should not be 
listed at the top level")
+
+       require.NoError(t, cat.DropNamespace(ctx, grandchild))
+       require.NoError(t, cat.DropNamespace(ctx, child1))
+
+       children, err = cat.ListNamespaces(ctx, parent)
+       require.NoError(t, err)
+       assert.ElementsMatch(t, []table.Identifier{child2}, children, "a 
dropped child should no longer be listed")
+
+       require.NoError(t, cat.DropNamespace(ctx, child2))
+
+       children, err = cat.ListNamespaces(ctx, parent)
+       require.NoError(t, err)
+       assert.Empty(t, children, "the parent should have no children left")
+}
+
+// testDropNamespaceWithNestedNamespace asserts that a namespace with a child
+// namespace cannot be dropped, that the rejected drop leaves both in place,
+// and that the two can be dropped child first.
+func testDropNamespaceWithNestedNamespace(t *testing.T, cfg Config) {
+       ctx := context.Background()
+       cat := cfg.NewCatalog(t)
+       parent, _ := newIdentifiers()
+       child := append(slices.Clone(parent), "child")
+
+       require.NoError(t, cat.CreateNamespace(ctx, parent, nil))
+       t.Cleanup(func() { _ = cat.DropNamespace(ctx, parent) })
+       require.NoError(t, cat.CreateNamespace(ctx, child, nil))
+       t.Cleanup(func() { _ = cat.DropNamespace(ctx, child) })
+
+       err := cat.DropNamespace(ctx, parent)
+       assert.ErrorIs(t, err, catalog.ErrNamespaceNotEmpty)
+
+       exists, err := cat.CheckNamespaceExists(ctx, parent)
+       require.NoError(t, err)
+       assert.True(t, exists, "the parent should still exist after a rejected 
drop")
+
+       exists, err = cat.CheckNamespaceExists(ctx, child)
+       require.NoError(t, err)
+       assert.True(t, exists, "the child should still exist after a rejected 
drop of its parent")
+
+       require.NoError(t, cat.DropNamespace(ctx, child))
+
+       exists, err = cat.CheckNamespaceExists(ctx, child)
+       require.NoError(t, err)
+       assert.False(t, exists, "the child should not exist after drop")
+
+       require.NoError(t, cat.DropNamespace(ctx, parent))
+
+       exists, err = cat.CheckNamespaceExists(ctx, parent)
+       require.NoError(t, err)
+       assert.False(t, exists, "the parent should not exist after drop")
+}
+
 // testNamespacePropertiesNotSupported asserts that a catalog which cannot 
store
 // namespace properties rejects writing them with iceberg.ErrNotImplemented and
 // that the rejected call changes nothing: creating with properties must not
diff --git a/catalog/hadoop/conformance_test.go 
b/catalog/hadoop/conformance_test.go
index 72e74eaa3..dc9a5b02e 100644
--- a/catalog/hadoop/conformance_test.go
+++ b/catalog/hadoop/conformance_test.go
@@ -29,6 +29,7 @@ import (
 
 func TestHadoopCatalogConformance(t *testing.T) {
        catalogtest.RunCatalogTests(t, catalogtest.Config{
+               SupportsNestedNamespaces: true,
                NewCatalog: func(t *testing.T) catalog.Catalog {
                        cat, err := hadoop.NewCatalog(context.Background(), 
"test", t.TempDir(), nil)
                        require.NoError(t, err)
diff --git a/catalog/rest/conformance_test.go b/catalog/rest/conformance_test.go
index 8e2c6192c..d1552de6b 100644
--- a/catalog/rest/conformance_test.go
+++ b/catalog/rest/conformance_test.go
@@ -34,6 +34,11 @@ func TestRestCatalogConformance(t *testing.T) {
        catalogtest.RunCatalogTests(t, catalogtest.Config{
                SupportsNamespaceProperties: true,
                SupportsRenameTable:         true,
+               // SupportsNestedNamespaces stays off: the published fixture 
(1.10.1)
+               // drops a namespace that still has children, which 
apache/iceberg#16061
+               // fixed in 1.11.0, and no newer fixture image is published yet.
+               // TODO(#1880): set SupportsNestedNamespaces once a published 
fixture
+               // includes apache/iceberg#16061.
                NewCatalog: func(t *testing.T) catalog.Catalog {
                        cat, err := catalog.Load(context.Background(), "local", 
iceberg.Properties{
                                "type":               "rest",
diff --git a/catalog/rest/external_conformance_test.go 
b/catalog/rest/external_conformance_test.go
index 8e9746cfd..36d070ae7 100644
--- a/catalog/rest/external_conformance_test.go
+++ b/catalog/rest/external_conformance_test.go
@@ -22,6 +22,7 @@ package rest_test
 import (
        "context"
        "os"
+       "strconv"
        "testing"
 
        "github.com/apache/iceberg-go"
@@ -48,6 +49,10 @@ const (
        // externalWarehouseEnv selects the warehouse, or the catalog for 
servers
        // such as Polaris that host several.
        externalWarehouseEnv = "REST_CATALOG_WAREHOUSE"
+       // externalNestedNamespacesEnv is a boolean that turns on the nested
+       // namespace tests. It is off by default because not every server 
follows
+       // Java's nested namespace behavior; CI sets it for Polaris.
+       externalNestedNamespacesEnv = "REST_CATALOG_NESTED_NAMESPACES"
 )
 
 // TestExternalRestCatalogConformance runs the catalog conformance suite 
against
@@ -71,9 +76,20 @@ func TestExternalRestCatalogConformance(t *testing.T) {
                props["warehouse"] = warehouse
        }
 
+       nestedNamespaces := false
+       if v := os.Getenv(externalNestedNamespacesEnv); v != "" {
+               var err error
+               nestedNamespaces, err = strconv.ParseBool(v)
+               require.NoError(t, err, "%s must be a boolean", 
externalNestedNamespacesEnv)
+       }
+       if !nestedNamespaces {
+               t.Logf("%s not set: skipping the nested namespace tests", 
externalNestedNamespacesEnv)
+       }
+
        catalogtest.RunCatalogTests(t, catalogtest.Config{
                SupportsNamespaceProperties: true,
                SupportsRenameTable:         true,
+               SupportsNestedNamespaces:    nestedNamespaces,
                NewCatalog: func(t *testing.T) catalog.Catalog {
                        cat, err := catalog.Load(context.Background(), 
"external", props)
                        require.NoError(t, err)
diff --git a/catalog/sql/conformance_test.go b/catalog/sql/conformance_test.go
index 94068a846..6857c7dbd 100644
--- a/catalog/sql/conformance_test.go
+++ b/catalog/sql/conformance_test.go
@@ -34,6 +34,8 @@ func TestSqlCatalogConformance(t *testing.T) {
        catalogtest.RunCatalogTests(t, catalogtest.Config{
                SupportsNamespaceProperties: true,
                SupportsRenameTable:         true,
+               // SupportsNestedNamespaces stays off until #2388: listing 
returns the
+               // parent and every descendant, and dropping a parent orphans 
its children.
                NewCatalog: func(t *testing.T) catalog.Catalog {
                        warehouse := t.TempDir()
 

Reply via email to