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 222908604 fix(catalog/sql)!: list direct child namespaces and refuse
dropping a parent (#2390)
222908604 is described below
commit 222908604006510b8e3dd5fafc0039381192157b
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sun Nov 15 21:27:19 2026 +0100
fix(catalog/sql)!: list direct child namespaces and refuse dropping a
parent (#2390)
Related #2388
---
catalog/catalog.go | 7 +-
catalog/sql/listing.go | 2 +-
catalog/sql/rename_view.go | 4 +-
catalog/sql/sql.go | 167 ++++++++++++++++++++++--------
catalog/sql/sql_test.go | 249 ++++++++++++++++++++++++++++++++++++++++-----
website/src/releases.md | 1 +
6 files changed, 361 insertions(+), 69 deletions(-)
diff --git a/catalog/catalog.go b/catalog/catalog.go
index cf7aa2652..1d8fd3d1c 100644
--- a/catalog/catalog.go
+++ b/catalog/catalog.go
@@ -142,12 +142,13 @@ type TableCatalog interface {
// NamespaceCatalog contains the namespace operations supported by every
// catalog. All built-in catalogs implement these operations.
type NamespaceCatalog interface {
- // ListNamespaces returns the list of available namespaces, optionally
filtering by a
- // parent namespace
+ // ListNamespaces returns the namespaces one level below parent, or the
+ // top-level namespaces when parent is empty.
ListNamespaces(ctx context.Context, parent table.Identifier)
([]table.Identifier, error)
// CreateNamespace tells the catalog to create a new namespace with the
given properties
CreateNamespace(ctx context.Context, namespace table.Identifier, props
iceberg.Properties) error
- // DropNamespace tells the catalog to drop the namespace and all tables
in that namespace
+ // DropNamespace drops an empty namespace. It returns
ErrNamespaceNotEmpty
+ // while the namespace holds tables, views, or child namespaces.
DropNamespace(ctx context.Context, namespace table.Identifier) error
// CheckNamespaceExists returns if the namespace exists
CheckNamespaceExists(ctx context.Context, namespace table.Identifier)
(bool, error)
diff --git a/catalog/sql/listing.go b/catalog/sql/listing.go
index 1fc751f59..93ab8c54a 100644
--- a/catalog/sql/listing.go
+++ b/catalog/sql/listing.go
@@ -81,7 +81,7 @@ func (c *Catalog) listObjectsAll(ctx context.Context,
namespace table.Identifier
if len(namespace) > 0 {
var exists bool
var err error
- ns, exists, err = c.resolveNamespaceKey(ctx, namespace)
+ ns, exists, err = c.resolveListableNamespaceKey(ctx, namespace)
if err != nil {
return nil, err
}
diff --git a/catalog/sql/rename_view.go b/catalog/sql/rename_view.go
index b3433371c..1188dedca 100644
--- a/catalog/sql/rename_view.go
+++ b/catalog/sql/rename_view.go
@@ -46,7 +46,7 @@ func (c *Catalog) RenameView(ctx context.Context, from, to
table.Identifier) (*v
if err != nil {
return nil, err
}
- toNamespace, exists, err := c.resolveNamespaceKey(ctx,
catalog.NamespaceFromIdent(to))
+ toNamespace, exists, err := c.resolveListableNamespaceKey(ctx,
catalog.NamespaceFromIdent(to))
if err != nil {
return nil, err
}
@@ -66,7 +66,7 @@ func (c *Catalog) RenameView(ctx context.Context, from, to
table.Identifier) (*v
if !sourceExists {
return fmt.Errorf("%w: %s", catalog.ErrNoSuchView, from)
}
- exists, err := c.namespaceExistsInTx(ctx, tx, toNamespace)
+ exists, err := c.listableNamespaceExistsInTx(ctx, tx,
catalog.NamespaceFromIdent(to), toNamespace)
if err != nil {
return err
}
diff --git a/catalog/sql/sql.go b/catalog/sql/sql.go
index c445fb21c..e3cd9ba91 100644
--- a/catalog/sql/sql.go
+++ b/catalog/sql/sql.go
@@ -129,14 +129,9 @@ func namespaceLikePrefix(prefix string) string {
return strings.NewReplacer("!", "!!", "%", "!%", "_",
"!_").Replace(prefix) + "%"
}
-func whereNamespaceParent(query *bun.SelectQuery, column string, parent
table.Identifier) *bun.SelectQuery {
+func whereNamespaceDescendant(query *bun.SelectQuery, column string, namespace
table.Identifier) *bun.SelectQuery {
return query.WhereGroup(" AND ", func(query *bun.SelectQuery)
*bun.SelectQuery {
- keys := namespaceStorageKeys(parent)
- query = query.Where("? = ?", bun.Ident(column), keys[0])
- for _, key := range keys[1:] {
- query = query.WhereOr("? = ?", bun.Ident(column), key)
- }
- for _, prefix := range namespaceDescendantPrefixes(parent) {
+ for _, prefix := range namespaceDescendantPrefixes(namespace) {
query = query.WhereOr("? LIKE ? ESCAPE '!'",
bun.Ident(column), namespaceLikePrefix(prefix))
}
@@ -822,7 +817,7 @@ func (c *Catalog) CreateTable(ctx context.Context, ident
table.Identifier, sc *i
nsIdent := catalog.NamespaceFromIdent(ident)
tblIdent := catalog.ObjectNameFromIdent(ident)
- ns, exists, err := c.resolveNamespaceKey(ctx, nsIdent)
+ ns, exists, err := c.resolveListableNamespaceKey(ctx, nsIdent)
if err != nil {
return nil, err
}
@@ -842,7 +837,7 @@ func (c *Catalog) CreateTable(ctx context.Context, ident
table.Identifier, sc *i
}
err = withSerializableWriteTx(ctx, c.db, func(ctx context.Context, tx
bun.Tx) error {
- exists, err := c.namespaceExistsInTx(ctx, tx, ns)
+ exists, err := c.listableNamespaceExistsInTx(ctx, tx, nsIdent,
ns)
if err != nil {
return err
}
@@ -962,7 +957,7 @@ func (c *Catalog) CommitTable(ctx context.Context, ident
table.Identifier, reqs
return nil
}
- exists, err := c.namespaceExistsInTx(ctx, tx, nsKey)
+ exists, err := c.listableNamespaceExistsInTx(ctx, tx, ns, nsKey)
if err != nil {
return err
}
@@ -1127,7 +1122,7 @@ func (c *Catalog) RenameTable(ctx context.Context, from,
to table.Identifier) (*
}
fromTbl := catalog.ObjectNameFromIdent(from)
- toNs, exists, err := c.resolveNamespaceKey(ctx,
catalog.NamespaceFromIdent(to))
+ toNs, exists, err := c.resolveListableNamespaceKey(ctx,
catalog.NamespaceFromIdent(to))
if err != nil {
return nil, err
}
@@ -1162,7 +1157,7 @@ func (c *Catalog) RenameTable(ctx context.Context, from,
to table.Identifier) (*
return fmt.Errorf("%w: %s", catalog.ErrNoSuchNamespace,
fromNs)
}
- destinationNamespaceExists, err := c.namespaceExistsInTx(ctx,
tx, toNs)
+ destinationNamespaceExists, err :=
c.listableNamespaceExistsInTx(ctx, tx, catalog.NamespaceFromIdent(to), toNs)
if err != nil {
return err
}
@@ -1345,6 +1340,14 @@ func (c *Catalog) DropNamespace(ctx context.Context,
namespace table.Identifier)
if err != nil {
return err
}
+
+ hasChildren, err := c.hasChildNamespaceInTx(ctx, tx, namespace)
+ if err != nil {
+ return fmt.Errorf("error checking namespace '%s' for
child namespaces: %w", nsToDelete, err)
+ }
+ if hasChildren {
+ return fmt.Errorf("%w: child namespaces exist in
namespace %s", catalog.ErrNamespaceNotEmpty, nsToDelete)
+ }
if !exists {
return fmt.Errorf("%w: %s", catalog.ErrNoSuchNamespace,
nsToDelete)
}
@@ -1377,7 +1380,7 @@ func (c *Catalog) LoadNamespaceProperties(ctx
context.Context, namespace table.I
return nil, err
}
- nsToLoad, exists, err := c.resolveNamespaceKey(ctx, namespace)
+ nsToLoad, exists, err := c.resolveListableNamespaceKey(ctx, namespace)
if err != nil {
return nil, err
}
@@ -1425,13 +1428,16 @@ func validateNamespacePropertyUpdates(removals
[]string, updates iceberg.Propert
}
func (c *Catalog) ListNamespaces(ctx context.Context, parent table.Identifier)
([]table.Identifier, error) {
- tableQuery := c.db.NewSelect().Model((*sqlIcebergTable)(nil)).
- Column("table_namespace").Where("catalog_name = ?", c.name)
- nsQuery := c.db.NewSelect().Model((*sqlIcebergNamespaceProps)(nil)).
- Column("namespace").Where("catalog_name = ?", c.name)
+ return withReadTx(ctx, c.db, func(ctx context.Context, tx bun.Tx)
([]table.Identifier, error) {
+ children, err := c.childNamespacesInTx(ctx, tx, parent)
+ if err != nil {
+ return nil, fmt.Errorf("error listing namespaces for
'%s': %w", parent, err)
+ }
+ if len(parent) == 0 || len(children) > 0 {
+ return children, nil
+ }
- if len(parent) > 0 {
- _, exists, err := c.resolveNamespaceKey(ctx, parent)
+ _, exists, err := c.resolveNamespaceKeyInTx(ctx, tx, parent)
if err != nil {
return nil, err
}
@@ -1439,38 +1445,119 @@ func (c *Catalog) ListNamespaces(ctx context.Context,
parent table.Identifier) (
return nil, fmt.Errorf("%w: %s",
catalog.ErrNoSuchNamespace, strings.Join(parent, "."))
}
- tableQuery = whereNamespaceParent(tableQuery,
"table_namespace", parent)
- nsQuery = whereNamespaceParent(nsQuery, "namespace", parent)
- }
+ return children, nil
+ })
+}
- namespaces, err := withReadTx(ctx, c.db, func(ctx context.Context, tx
bun.Tx) ([]string, error) {
- var namespaces []string
+// childNamespacesInTx returns the namespaces one level below parent, or the
+// distinct first levels when parent is empty, as Java's JdbcCatalog does.
+// A namespace counts if it has properties of its own or holds a table or view
+// anywhere below it.
+func (c *Catalog) childNamespacesInTx(ctx context.Context, tx bun.Tx, parent
table.Identifier) ([]table.Identifier, error) {
+ ret := make([]table.Identifier, 0)
+ seen := make(map[string]struct{})
+ err := c.walkNamespacesBelowInTx(ctx, tx, parent, " UNION ", func(child
table.Identifier) bool {
+ key := namespaceToString(child)
+ if _, ok := seen[key]; !ok {
+ seen[key] = struct{}{}
+ ret = append(ret, child)
+ }
+
+ return true
+ })
+ if err != nil {
+ return nil, err
+ }
- rows, err := tx.QueryContext(ctx, tableQuery.String()+" UNION
"+nsQuery.String())
- if err != nil {
- return nil, fmt.Errorf("error listing namespaces for
'%s': %w", parent, err)
- }
+ return ret, nil
+}
- err = c.db.ScanRows(ctx, rows, &namespaces)
+// hasChildNamespaceInTx reports whether childNamespacesInTx would return
+// anything, and stops reading at the first row that says so.
+func (c *Catalog) hasChildNamespaceInTx(ctx context.Context, tx bun.Tx, parent
table.Identifier) (bool, error) {
+ found := false
+ // UNION ALL lets the database hand over the first row without
+ // deduplicating the rest.
+ err := c.walkNamespacesBelowInTx(ctx, tx, parent, " UNION ALL ",
func(table.Identifier) bool {
+ found = true
- return namespaces, err
+ return false
})
+
+ return found, err
+}
+
+// walkNamespacesBelowInTx calls yield with the direct child of parent that
+// each stored namespace below parent belongs to, repeats included, until
+// yield returns false. LIKE ignores case on some databases, so the levels are
+// compared exactly here and not in the query.
+func (c *Catalog) walkNamespacesBelowInTx(ctx context.Context, tx bun.Tx,
parent table.Identifier, union string, yield func(table.Identifier) bool) error
{
+ tableQuery := tx.NewSelect().Model((*sqlIcebergTable)(nil)).
+ Column("table_namespace").Where("catalog_name = ?", c.name)
+ nsQuery := tx.NewSelect().Model((*sqlIcebergNamespaceProps)(nil)).
+ Column("namespace").Where("catalog_name = ?", c.name)
+ if len(parent) > 0 {
+ tableQuery = whereNamespaceDescendant(tableQuery,
"table_namespace", parent)
+ nsQuery = whereNamespaceDescendant(nsQuery, "namespace", parent)
+ }
+
+ rows, err := tx.QueryContext(ctx,
tableQuery.String()+union+nsQuery.String())
if err != nil {
- return nil, err
+ return err
}
+ defer rows.Close()
- ret := make([]table.Identifier, 0, len(namespaces))
- for _, n := range namespaces {
+ for rows.Next() {
+ var n string
+ if err := rows.Scan(&n); err != nil {
+ return err
+ }
ident, err := namespaceFromString(n)
if err != nil {
- return nil, err
+ return err
}
- if len(parent) == 0 || (len(ident) >= len(parent) &&
slices.Equal(ident[:len(parent)], parent)) {
- ret = append(ret, ident)
+ if len(ident) <= len(parent) ||
!slices.Equal(ident[:len(parent)], parent) {
+ continue
+ }
+ if !yield(ident[:len(parent)+1]) {
+ return nil
}
}
- return ret, nil
+ return rows.Err()
+}
+
+// resolveListableNamespaceKey is resolveNamespaceKey for read operations and
+// for creating tables and views in a namespace or renaming them into it, where
+// a namespace also exists while it has child namespaces, even without a row of
+// its own. CreateNamespace
+// and UpdateNamespaceProperties keep the exact check, so CreateNamespace is
+// how such a namespace gets a row.
+func (c *Catalog) resolveListableNamespaceKey(ctx context.Context, namespace
table.Identifier) (string, bool, error) {
+ key, exists, err := c.resolveNamespaceKey(ctx, namespace)
+ if err != nil || exists || len(namespace) == 0 {
+ return key, exists, err
+ }
+
+ hasChildren, err := withReadTx(ctx, c.db, func(ctx context.Context, tx
bun.Tx) (bool, error) {
+ return c.hasChildNamespaceInTx(ctx, tx, namespace)
+ })
+ if err != nil {
+ return "", false, err
+ }
+
+ return key, hasChildren, nil
+}
+
+// listableNamespaceExistsInTx is the in-transaction counterpart of
+// resolveListableNamespaceKey for a storage key it already resolved.
+func (c *Catalog) listableNamespaceExistsInTx(ctx context.Context, tx bun.Tx,
namespace table.Identifier, key string) (bool, error) {
+ exists, err := c.namespaceExistsInTx(ctx, tx, key)
+ if err != nil || exists || len(namespace) == 0 {
+ return exists, err
+ }
+
+ return c.hasChildNamespaceInTx(ctx, tx, namespace)
}
func (c *Catalog) UpdateNamespaceProperties(ctx context.Context, namespace
table.Identifier, removals []string, updates iceberg.Properties)
(catalog.PropertiesUpdateSummary, error) {
@@ -1564,7 +1651,7 @@ func (c *Catalog) UpdateNamespaceProperties(ctx
context.Context, namespace table
}
func (c *Catalog) CheckNamespaceExists(ctx context.Context, namespace
table.Identifier) (bool, error) {
- _, exists, err := c.resolveNamespaceKey(ctx, namespace)
+ _, exists, err := c.resolveListableNamespaceKey(ctx, namespace)
return exists, err
}
@@ -1581,7 +1668,7 @@ func (c *Catalog) CreateView(ctx context.Context,
identifier table.Identifier, v
nsIdent := catalog.NamespaceFromIdent(identifier)
viewIdent := catalog.ObjectNameFromIdent(identifier)
- ns, exists, err := c.resolveNamespaceKey(ctx, nsIdent)
+ ns, exists, err := c.resolveListableNamespaceKey(ctx, nsIdent)
if err != nil {
return nil, err
}
@@ -1618,7 +1705,7 @@ func (c *Catalog) CreateView(ctx context.Context,
identifier table.Identifier, v
metadataLocation := createdView.MetadataLocation()
err = withSerializableWriteTx(ctx, c.db, func(ctx context.Context, tx
bun.Tx) error {
- exists, err := c.namespaceExistsInTx(ctx, tx, ns)
+ exists, err := c.listableNamespaceExistsInTx(ctx, tx, nsIdent,
ns)
if err != nil {
return err
}
diff --git a/catalog/sql/sql_test.go b/catalog/sql/sql_test.go
index 732ab15c2..fb10b4468 100644
--- a/catalog/sql/sql_test.go
+++ b/catalog/sql/sql_test.go
@@ -1182,30 +1182,233 @@ func (s *SqliteCatalogTestSuite) TestListNamespaces() {
s.Require().NoError(cat.CreateNamespace(ctx, ns1, nil))
s.Require().NoError(cat.CreateNamespace(ctx, ns2, nil))
+ // The root lists first levels only, so ns2 appears as its
first level.
nslist, err := cat.ListNamespaces(ctx, nil)
s.Require().NoError(err)
- s.Len(nslist, 2)
- s.Contains(nslist, ns1)
- s.Contains(nslist, ns2)
+ s.ElementsMatch([]table.Identifier{ns1, ns2[:1]}, nslist)
ns, err := cat.ListNamespaces(ctx, ns1)
s.Require().NoError(err)
- s.Len(ns, 1)
- s.Equal(ns1, ns[0])
+ s.Empty(ns)
ns, err = cat.ListNamespaces(ctx, ns2)
s.Require().NoError(err)
- s.Len(ns, 1)
- s.Equal(ns2, ns[0])
+ s.Empty(ns)
_, err = cat.ListNamespaces(ctx,
table.Identifier{"does_not_exist"})
s.ErrorIs(err, catalog.ErrNoSuchNamespace)
- ns, err = cat.ListNamespaces(ctx, nil)
+ // A parent created only through its child is listed, and
exists for
+ // every read, so the hierarchy can be walked from the root.
+ implied := table.Identifier{databaseName()}
+ impliedChild := append(slices.Clone(implied), "child")
+ s.Require().NoError(cat.CreateNamespace(ctx, impliedChild, nil))
+
+ nslist, err = cat.ListNamespaces(ctx, nil)
+ s.Require().NoError(err)
+ s.Contains(nslist, implied)
+ ns, err = cat.ListNamespaces(ctx, implied)
+ s.Require().NoError(err)
+ s.Equal([]table.Identifier{impliedChild}, ns)
+ ns, err = cat.ListNamespaces(ctx, impliedChild)
+ s.Require().NoError(err)
+ s.Empty(ns)
+
+ exists, err := cat.CheckNamespaceExists(ctx, implied)
+ s.Require().NoError(err)
+ s.True(exists)
+ exists, err = cat.CheckNamespaceExists(ctx, nil)
+ s.Require().NoError(err)
+ s.False(exists)
+ props, err := cat.LoadNamespaceProperties(ctx, implied)
+ s.Require().NoError(err)
+ s.Empty(props)
+ for _, err := range cat.ListTables(ctx, implied) {
+ s.Require().NoError(err)
+ }
+ for _, err := range cat.ListViews(ctx, implied) {
+ s.Require().NoError(err)
+ }
+ s.ErrorIs(cat.DropNamespace(ctx, implied),
catalog.ErrNamespaceNotEmpty)
+
+ // Creating the parent itself still succeeds.
+ s.Require().NoError(cat.CreateNamespace(ctx, implied, nil))
+ s.ErrorIs(cat.CreateNamespace(ctx, implied, nil),
catalog.ErrNamespaceAlreadyExists)
+ }
+}
+
+func (s *SqliteCatalogTestSuite) TestCreateInNamespaceWithOnlyChildren() {
+ for _, cat := range []*sqlcat.Catalog{s.getCatalogMemory(),
s.getCatalogSqlite()} {
+ ctx := context.Background()
+ schema := iceberg.NewSchema(1, iceberg.NestedField{
+ ID: 1, Name: "id", Type: iceberg.PrimitiveTypes.Int32,
Required: true,
+ })
+
+ // Each operation gets its own namespace that has only a child
and no
+ // row of its own, so one operation's table row cannot satisfy
another
+ // operation's existence check.
+ childrenOnly := func() table.Identifier {
+ ns := table.Identifier{databaseName()}
+ s.Require().NoError(cat.CreateNamespace(ctx,
append(slices.Clone(ns), "child"), nil))
+
+ exists, err := cat.CheckNamespaceExists(ctx, ns)
+ s.Require().NoError(err)
+ s.Require().True(exists)
+
+ return ns
+ }
+
+ // CheckNamespaceExists is true, so tables and views can be
created
+ // there, and a table can be renamed into it.
+ createNS := childrenOnly()
+ _, err := cat.CreateTable(ctx, append(slices.Clone(createNS),
tableName()), tableSchemaNested)
+ s.Require().NoError(err)
+
+ renameNS := childrenOnly()
+ other := table.Identifier{databaseName()}
+ s.Require().NoError(cat.CreateNamespace(ctx, other, nil))
+ moved := append(slices.Clone(renameNS), tableName())
+ _, err = cat.CreateTable(ctx, append(slices.Clone(other),
tableName()), tableSchemaNested)
+ s.Require().NoError(err)
+ for id, err := range cat.ListTables(ctx, other) {
+ s.Require().NoError(err)
+ _, err = cat.RenameTable(ctx, id, moved)
+ s.Require().NoError(err)
+ }
+
+ viewNS := childrenOnly()
+ createdView := append(slices.Clone(viewNS), tableName())
+ s.Require().NoError(createTestView(ctx, cat, createdView,
schema,
+ view.Representation{SQL: "SELECT 1", Dialect: "spark"},
nil))
+
+ renameViewNS := childrenOnly()
+ movedView := append(slices.Clone(renameViewNS), tableName())
+ _, err = cat.RenameView(ctx, createdView, movedView)
+ s.Require().NoError(err)
+
+ commitNS := childrenOnly()
+ _, _, err = cat.CommitTable(ctx, append(slices.Clone(commitNS),
tableName()),
+ []table.Requirement{table.AssertCreate()},
[]table.Update{
+
table.NewSetLocationUpdate("file:///tmp/warehouse/" + strings.Join(commitNS,
"/")),
+ })
s.Require().NoError(err)
- s.Len(ns, 2)
- s.Equal(ns1, ns[0])
- s.Equal(ns2, ns[1])
+
+ // A namespace with neither a row nor children still does not
exist.
+ missing := table.Identifier{databaseName()}
+ _, err = cat.CreateTable(ctx, append(slices.Clone(missing),
tableName()), tableSchemaNested)
+ s.ErrorIs(err, catalog.ErrNoSuchNamespace)
+ _, err = cat.RenameTable(ctx, moved,
append(slices.Clone(missing), tableName()))
+ s.ErrorIs(err, catalog.ErrNoSuchNamespace)
+ s.ErrorIs(createTestView(ctx, cat,
append(slices.Clone(missing), tableName()), schema,
+ view.Representation{SQL: "SELECT 1", Dialect: "spark"},
nil), catalog.ErrNoSuchNamespace)
+ _, err = cat.RenameView(ctx, movedView,
append(slices.Clone(missing), tableName()))
+ s.ErrorIs(err, catalog.ErrNoSuchNamespace)
+ _, _, err = cat.CommitTable(ctx, append(slices.Clone(missing),
tableName()),
+ []table.Requirement{table.AssertCreate()},
[]table.Update{
+
table.NewSetLocationUpdate("file:///tmp/warehouse/" + strings.Join(missing,
"/")),
+ })
+ s.ErrorIs(err, catalog.ErrNoSuchNamespace)
+ }
+}
+
+func (s *SqliteCatalogTestSuite) TestDropNamespaceWithChildOnlyInTableRow() {
+ cat := s.getCatalogSqlite()
+ ctx := context.Background()
+ parent := table.Identifier{databaseName()}
+ child := append(slices.Clone(parent), "child")
+ s.Require().NoError(cat.CreateNamespace(ctx, parent, nil))
+ s.Require().NoError(cat.CreateNamespace(ctx, child, nil))
+ _, err := cat.CreateTable(ctx, append(slices.Clone(child),
tableName()), tableSchemaNested)
+ s.Require().NoError(err)
+
+ // Leave the child only in iceberg_tables, as catalogs without
+ // namespace property rows do.
+ sqldb := s.getDB()
+ defer sqldb.Close()
+ _, err = sqldb.Exec(`DELETE FROM iceberg_namespace_properties WHERE
catalog_name = ? AND namespace = ?`,
+ cat.Name(), strings.Join(child, "."))
+ s.Require().NoError(err)
+
+ children, err := cat.ListNamespaces(ctx, parent)
+ s.Require().NoError(err)
+ s.Equal([]table.Identifier{child}, children)
+ s.ErrorIs(cat.DropNamespace(ctx, parent), catalog.ErrNamespaceNotEmpty)
+}
+
+func (s *SqliteCatalogTestSuite) TestDropNamespaceWithDottedChild() {
+ for _, cat := range []*sqlcat.Catalog{s.getCatalogMemory(),
s.getCatalogSqlite()} {
+ ctx := context.Background()
+ parent := table.Identifier{databaseName()}
+ // The dotted level forces the JSON-encoded storage key.
+ child := append(slices.Clone(parent), "x.y")
+ s.Require().NoError(cat.CreateNamespace(ctx, parent, nil))
+ s.Require().NoError(cat.CreateNamespace(ctx, child, nil))
+
+ children, err := cat.ListNamespaces(ctx, parent)
+ s.Require().NoError(err)
+ s.Equal([]table.Identifier{child}, children)
+ s.ErrorIs(cat.DropNamespace(ctx, parent),
catalog.ErrNamespaceNotEmpty)
+
+ s.Require().NoError(cat.DropNamespace(ctx, child))
+ s.Require().NoError(cat.DropNamespace(ctx, parent))
+ }
+}
+
+func (s *SqliteCatalogTestSuite) TestNamespaceLevelsCompareCase() {
+ for _, cat := range []*sqlcat.Catalog{s.getCatalogMemory(),
s.getCatalogSqlite()} {
+ ctx := context.Background()
+ lower := table.Identifier{databaseName()}
+ // SQLite's LIKE ignores ASCII case, so the query alone would
treat
+ // this as a child of lower.
+ upperChild := table.Identifier{strings.ToUpper(lower[0]), "eu"}
+ s.Require().NoError(cat.CreateNamespace(ctx, lower, nil))
+ s.Require().NoError(cat.CreateNamespace(ctx, upperChild, nil))
+
+ root, err := cat.ListNamespaces(ctx, nil)
+ s.Require().NoError(err)
+ s.ElementsMatch([]table.Identifier{lower, upperChild[:1]}, root)
+ children, err := cat.ListNamespaces(ctx, lower)
+ s.Require().NoError(err)
+ s.Empty(children)
+ s.ErrorIs(cat.DropNamespace(ctx, upperChild[:1]),
catalog.ErrNamespaceNotEmpty)
+ s.Require().NoError(cat.DropNamespace(ctx, lower))
+
+ exists, err := cat.CheckNamespaceExists(ctx, lower)
+ s.Require().NoError(err)
+ s.False(exists)
+ exists, err = cat.CheckNamespaceExists(ctx, upperChild[:1])
+ s.Require().NoError(err)
+ s.True(exists)
+ }
+}
+
+func (s *SqliteCatalogTestSuite) TestNestedNamespaces() {
+ catalogs := []*sqlcat.Catalog{s.getCatalogMemory(),
s.getCatalogSqlite()}
+
+ for _, cat := range catalogs {
+ ctx := context.Background()
+ parent := table.Identifier{databaseName()}
+ child := append(slices.Clone(parent), "child")
+ grandchild := append(slices.Clone(child), "grandchild")
+ for _, ns := range []table.Identifier{parent, child,
grandchild} {
+ s.Require().NoError(cat.CreateNamespace(ctx, ns, nil))
+ }
+
+ root, err := cat.ListNamespaces(ctx, nil)
+ s.Require().NoError(err)
+ s.Equal([]table.Identifier{parent}, root)
+ children, err := cat.ListNamespaces(ctx, parent)
+ s.Require().NoError(err)
+ s.Equal([]table.Identifier{child}, children)
+ children, err = cat.ListNamespaces(ctx, child)
+ s.Require().NoError(err)
+ s.Equal([]table.Identifier{grandchild}, children)
+
+ s.ErrorIs(cat.DropNamespace(ctx, parent),
catalog.ErrNamespaceNotEmpty)
+ s.ErrorIs(cat.DropNamespace(ctx, child),
catalog.ErrNamespaceNotEmpty)
+ for _, ns := range []table.Identifier{grandchild, child,
parent} {
+ s.Require().NoError(cat.DropNamespace(ctx, ns))
+ }
}
}
@@ -1224,19 +1427,21 @@ func (s *SqliteCatalogTestSuite)
TestDottedNamespaceComponentsRemainDistinct() {
s.Require().NoError(cat.CreateNamespace(ctx, dottedChild, nil))
s.Require().NoError(cat.CreateNamespace(ctx, hierarchicalChild,
nil))
+ // "company_.<tag>" is one level of dotted, but only a prefix of
+ // hierarchical's first two levels, so the root lists both
separately.
namespaces, err := cat.ListNamespaces(ctx, nil)
s.Require().NoError(err)
- s.Contains(namespaces, dotted)
- s.Contains(namespaces, hierarchical)
- s.Contains(namespaces, dottedChild)
- s.Contains(namespaces, hierarchicalChild)
+ s.Contains(namespaces, dotted[:1])
+ s.Contains(namespaces, hierarchical[:1])
+ s.NotContains(namespaces, dotted)
+ s.NotContains(namespaces, hierarchical)
dottedNamespaces, err := cat.ListNamespaces(ctx, dotted)
s.Require().NoError(err)
- s.ElementsMatch([]table.Identifier{dotted, dottedChild},
dottedNamespaces)
+ s.ElementsMatch([]table.Identifier{dottedChild},
dottedNamespaces)
hierarchicalNamespaces, err := cat.ListNamespaces(ctx,
hierarchical)
s.Require().NoError(err)
- s.ElementsMatch([]table.Identifier{hierarchical,
hierarchicalChild}, hierarchicalNamespaces)
+ s.ElementsMatch([]table.Identifier{hierarchicalChild},
hierarchicalNamespaces)
dottedProps, err := cat.LoadNamespaceProperties(ctx, dotted)
s.Require().NoError(err)
@@ -1334,7 +1539,7 @@ func (s *SqliteCatalogTestSuite)
TestLegacyNamespaceEncodingPrefixRemainsReadabl
s.True(exists)
children, err := cat.ListNamespaces(ctx, legacyIdent)
s.Require().NoError(err)
- s.Contains(children, legacyIdent)
+ s.Empty(children)
props, err := cat.LoadNamespaceProperties(ctx, legacyIdent)
s.Require().NoError(err)
s.Equal("legacy", props["owner"])
@@ -1372,7 +1577,7 @@ func (s *SqliteCatalogTestSuite)
TestListNamespacesEscapesLikeWildcards() {
namespaces, err := cat.ListNamespaces(ctx, parent)
s.Require().NoError(err)
- s.ElementsMatch([]table.Identifier{parent, child}, namespaces)
+ s.ElementsMatch([]table.Identifier{child}, namespaces)
s.Require().NoError(cat.DropNamespace(ctx, child))
s.Require().NoError(cat.DropNamespace(ctx, parent))
@@ -2550,8 +2755,7 @@ func (s *SqliteCatalogTestSuite)
TestCreateaNamespaceWithCommentAndLocation() {
s.Require().NoError(tt.cat.CreateNamespace(ctx, tt.namespace,
testProps))
loadedList, err := tt.cat.ListNamespaces(ctx, nil)
s.Require().NoError(err)
- s.Len(loadedList, 1)
- s.Equal(tt.namespace, loadedList[0])
+ s.Equal([]table.Identifier{tt.namespace[:1]}, loadedList)
props, err := tt.cat.LoadNamespaceProperties(ctx, tt.namespace)
s.Require().NoError(err)
@@ -2577,8 +2781,7 @@ func (s *SqliteCatalogTestSuite) TestDropNamespace() {
nslist, err := tt.cat.ListNamespaces(ctx, nil)
s.Require().NoError(err)
- s.Len(nslist, 1)
- s.Equal(ns, nslist[0])
+ s.Equal([]table.Identifier{ns[:1]}, nslist)
_, err = tt.cat.CreateTable(ctx, tt.tblID, tableSchemaNested)
s.Require().NoError(err)
diff --git a/website/src/releases.md b/website/src/releases.md
index b65d22df1..cbd5af17a 100644
--- a/website/src/releases.md
+++ b/website/src/releases.md
@@ -72,6 +72,7 @@ Per-release notes (highlights, breaking changes,
contributors) are published on
- **`LocationProvider.NewDataLocation` takes the partition path.** The method
is now `NewDataLocation(dataFileName, partitionPath string)`, matching Iceberg
Java and PyIceberg, so custom `LocationProvider` implementations must add the
argument. Callers pass the partition path there, or `""` for an unpartitioned
file, instead of prefixing the file name.
- **Partitioned data files follow the table's location provider.** With
`write.object-storage.enabled=true` and the default
`write.object-storage.partitioned-paths=true`, new partitioned files land under
`data/<hash>/<partition>/` instead of `data/<partition>/<hash>/`, which can
affect prefix-based lifecycle rules and bucket policies.
`write.object-storage.partitioned-paths=false` and `write.data.path` now apply
to partitioned writes. Partitioned paths also no longer percent-encode the t
[...]
- **External object-store data paths include table context.** For
object-storage tables whose `write.data.path` is outside the table location,
new data files now use `<hash>/<db>/<table>/...` after the shared storage
prefix. This applies whether `write.object-storage.partitioned-paths` is `true`
or `false`. The new prefixes may affect prefix-based lifecycle rules and bucket
policies. Existing data files do not move.
+- **SQL catalog nested namespaces match the JDBC catalog.**
`sql.Catalog.ListNamespaces(ctx, parent)` returns only the direct children of
`parent`, no longer `parent` itself or deeper descendants, and
`ListNamespaces(ctx, nil)` returns the distinct first levels. A namespace that
has no row of its own but has child namespaces, such as `a` after
`CreateNamespace(a.b)`, now exists for listing, `CheckNamespaceExists`,
`LoadNamespaceProperties`, `CreateTable`, `CreateView`, `CommitTable` crea [...]
- **Catalog capabilities split into narrower interfaces.** `catalog.Catalog`
now embeds `TableCatalog` and `NamespaceCatalog` with unchanged table and
namespace methods. `Name() string` is now required, breaking third-party
catalogs and test fakes. `ViewCatalog` is optional (REST, Hive, and SQL), while
REST, SQL, and Hive implement `UpdatableViewCatalog` for `UpdateView`. REST and
SQL implement `RenamableViewCatalog` for `RenameView`. Use `catalog.As[T](cat)`
and the `Unwrap() Catalog` c [...]
- **Rename IO methods take a context.** `RenameIO.Rename` and
`RenameNoReplaceIO.RenameNoReplace` now take `context.Context` first, so custom
implementations and callers must update.
- **`ReplaceFilesWithDeleteFiles` removed.** For delete-file replacements, use
`tx.NewRewrite(snapshotProps)`, call `DeleteFile` for each source file and
`AddDeleteFileWithDataSequenceNumber` for each replacement, then commit the
builder. Rewrites record a `replace` snapshot instead of `overwrite`. The
five-argument `ReplaceFiles` API is unchanged and remains available for
compaction and delete-file removals.